private CodeImport GetImport(CodeElements codeElements) { List <CodeElement2> elements = codeElements.Cast <CodeElement2>().ToList(); CodeImport imp = elements.FirstOrDefault(codeElement => codeElement.Kind == vsCMElement.vsCMElementIDLImport) as CodeImport; return(imp); }
private static string GetNamespace(CodeElements attrs) { if (attrs == null) { return(DefaultModuleName); } var namespaceFromAttr = from a in attrs.Cast <CodeAttribute2>() where a.Name.EndsWith(ModuleNameAttributeName, StringComparison.OrdinalIgnoreCase) from arg in a.Arguments.Cast <CodeAttributeArgument>() let v = (arg.Value ?? "").Trim('\"') where !string.IsNullOrWhiteSpace(v) select v; return(namespaceFromAttr.FirstOrDefault() ?? DefaultModuleName); }
private static CodeElement GetCodeElementAtTextPoint(vsCMElement eRequestedCodeElementKind, CodeElements colCodeElements, EnvDTE.TextPoint objTextPoint) { CodeElement objResultCodeElement = null; if (colCodeElements == null) { return(null); } foreach (var objCodeElement in colCodeElements.Cast <CodeElement>()) { if (objCodeElement.StartPoint.GreaterThan(objTextPoint)) { // The code element starts beyond the point } else if (objCodeElement.EndPoint.LessThan(objTextPoint)) { // The code element ends before the point // The code element contains the point } else { if (objCodeElement.Kind == eRequestedCodeElementKind) { // Found objResultCodeElement = objCodeElement; } // We enter in recursion, just in case there is an inner code element that also // satisfies the conditions, for example, if we are searching a namespace or a class var colCodeElementMembers = GetCodeElementMembers(objCodeElement); var objMemberCodeElement = GetCodeElementAtTextPoint(eRequestedCodeElementKind, colCodeElementMembers, objTextPoint); if ((objMemberCodeElement != null)) { // A nested code element also satisfies the conditions objResultCodeElement = objMemberCodeElement; } break; } } return(objResultCodeElement); }
/// <summary> /// 获取类 /// </summary> /// <param name="codeElements"></param> /// <returns></returns> private CodeClass2 GetClass(CodeElements codeElements) { List <CodeElement2> elements = codeElements.Cast <CodeElement2>().ToList(); CodeClass2 result = elements.FirstOrDefault(codeElement => codeElement.Kind == vsCMElement.vsCMElementClass) as CodeClass2; if (result != null) { return(result); } foreach (CodeElement2 codeElement in elements) { result = GetClass(codeElement.Children); if (result != null) { return(result); } } return(null); }
/// <summary> /// 获取类 /// </summary> /// <param name="codeElements"></param> /// <returns></returns> public static CodeClass GetClass(CodeElements codeElements) { var elements = codeElements.Cast <CodeElement>().ToList(); var result = elements.FirstOrDefault(codeElement => codeElement.Kind == vsCMElement.vsCMElementClass) as CodeClass; if (result != null) { return(result); } foreach (var codeElement in elements) { result = GetClass(codeElement.Children); if (result != null) { return(result); } } return(null); }
/// <summary> /// 获取类 /// </summary> /// <param name="codeElements"></param> /// <returns></returns> private static CodeClass GetClass(CodeElements codeElements) { ThreadHelper.ThrowIfNotOnUIThread(); List <CodeElement> elements = codeElements.Cast <CodeElement>().ToList(); if (elements.FirstOrDefault(codeElement => { ThreadHelper.ThrowIfNotOnUIThread(); return(codeElement.Kind == vsCMElement.vsCMElementClass); }) is CodeClass result) { return(result); } foreach (var codeElement in elements) { result = GetClass(codeElement.Children); if (result != null) { return(result); } } return(null); }
private static CodeElement GetCodeElementAtTextPoint(vsCMElement eRequestedCodeElementKind, CodeElements colCodeElements, EnvDTE.TextPoint objTextPoint) { CodeElement objResultCodeElement = null; if (colCodeElements == null) return null; foreach (var objCodeElement in colCodeElements.Cast<CodeElement>()) { if (objCodeElement.StartPoint.GreaterThan(objTextPoint)) { // The code element starts beyond the point } else if (objCodeElement.EndPoint.LessThan(objTextPoint)) { // The code element ends before the point // The code element contains the point } else { if (objCodeElement.Kind == eRequestedCodeElementKind) { // Found objResultCodeElement = objCodeElement; } // We enter in recursion, just in case there is an inner code element that also // satisfies the conditions, for example, if we are searching a namespace or a class var colCodeElementMembers = GetCodeElementMembers(objCodeElement); var objMemberCodeElement = GetCodeElementAtTextPoint(eRequestedCodeElementKind, colCodeElementMembers, objTextPoint); if ((objMemberCodeElement != null)) { // A nested code element also satisfies the conditions objResultCodeElement = objMemberCodeElement; } break; } } return objResultCodeElement; }
/// <summary> /// 获取类 /// </summary> /// <param name="codeElements"></param> /// <returns></returns> public static CodeClass GetClass(CodeElements codeElements) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); var elements = codeElements.Cast <CodeElement>().ToList(); var result = elements.FirstOrDefault(codeElement => codeElement.Kind == vsCMElement.vsCMElementClass) as CodeClass; if (result != null) { return(result); } foreach (var codeElement in elements) { result = GetClass(codeElement.Children); if (result != null) { return(result); } } return(null); }
private CodeClass GetClass(CodeElements codeElements) { var elements = codeElements.Cast<CodeElement>().ToList(); var result = elements.FirstOrDefault(codeElement => codeElement.Kind == vsCMElement.vsCMElementClass) as CodeClass; if (result != null) { return result; } foreach (var codeElement in elements) { result = GetClass(codeElement.Children); if (result != null) { return result; } } return null; }
private static string GetNamespace(CodeElements attrs) { if (attrs == null) return DefaultModuleName; var namespaceFromAttr = from a in attrs.Cast<CodeAttribute2>() where a.Name.EndsWith(ModuleNameAttributeName, StringComparison.OrdinalIgnoreCase) from arg in a.Arguments.Cast<CodeAttributeArgument>() let v = (arg.Value ?? "").Trim('\"') where !string.IsNullOrWhiteSpace(v) select v; return namespaceFromAttr.FirstOrDefault() ?? DefaultModuleName; }
/// <summary> /// Extends elements by given part constraint (if constraint is <c>null</c> all elements are returned). /// </summary> /// <param name="elements">Elements to be extended.</param> /// <param name="part">Extending part constraint.</param> /// <returns>Extended element positions.</returns> public static IEnumerable <ElementPosition> ExtendElements(CodeElements elements, string part) { return(ExtendElements(elements.Cast <CodeElement>(), part)); }