/// <summary> /// Gets the code element. /// </summary> /// <param name="vs">The vs.</param> /// <param name="fileCodeModel">The file code model.</param> /// <param name="codeElementType">Type of the code element.</param> /// <returns></returns> public static object GetCodeElement(DTE vs, EnvDTE.FileCodeModel fileCodeModel, Type codeElementType) { TextSelection textSelection = (TextSelection)vs.ActiveDocument.Selection; TextPoint point = textSelection.ActivePoint; object element; if(codeElementType.IsAssignableFrom(typeof(CodeNamespace))) { try { element = (CodeNamespace)fileCodeModel.CodeElementFromPoint( point, vsCMElement.vsCMElementNamespace); return element; } catch { return null; } } if(codeElementType.IsAssignableFrom(typeof(CodeAttribute))) { try { element = (CodeAttribute)fileCodeModel.CodeElementFromPoint( point, vsCMElement.vsCMElementAttribute); return element; } catch { return null; } } if(codeElementType.IsAssignableFrom(typeof(CodeClass))) { try { element = (CodeClass)fileCodeModel.CodeElementFromPoint( point, vsCMElement.vsCMElementClass); return element; } catch { return null; } } if(codeElementType.IsAssignableFrom(typeof(CodeProperty))) { try { element = (CodeProperty)fileCodeModel.CodeElementFromPoint( point, vsCMElement.vsCMElementProperty); return element; } catch { return null; } } if(codeElementType.IsAssignableFrom(typeof(CodeFunction))) { try { element = (CodeFunction)fileCodeModel.CodeElementFromPoint( point, vsCMElement.vsCMElementFunction); return element; } catch { return null; } } return null; }