private static List<TypeAndNamespace> getDeclaredElements(string word, ICSharpTypeMemberDeclaration declaration, ISolution solution, IdentifierLookupScopes scope = IdentifierLookupScopes.ProjectAndReferencedLibraries) { //solution.GetPsiServices().SolutionProject.ProjectFile. //IModuleReferenceResolveContext context = declaration.DeclaredElement.GetResolveContext(); IClrDeclaredElement[] declaredElements = solution.GetPsiServices() .Symbols.GetSymbolScope(scope.AsLibrarySymbolScope(), true) .GetElementsByShortName(word); return getTypeAndNamespaces(declaredElements, declaration, solution, scope); }
public static string ContractCRef(string input, ICSharpTypeMemberDeclaration declaration, ISolution solution, IdentifierLookupScopes scope = IdentifierLookupScopes.ProjectAndReferencedLibraries) { string methodArgs = null; string methodName = null; string crefText = input; if (crefText == null) return null; if (crefText.Length > 2 && crefText[1] == ':') { if (crefText[0] == 'M' || crefText.Contains("(")) { methodArgs = crefText.Substring(crefText.IndexOf('(')); crefText = crefText.Substring(0, crefText.IndexOf('(')); methodName = crefText.Substring(crefText.LastIndexOf('.') + 1); crefText = crefText.Substring(0, crefText.LastIndexOf('.')); } crefText = crefText.Substring(2); } //IModuleReferenceResolveContext context = declaration.DeclaredElement.GetResolveContext(); ICollection<IClrDeclaredElement> declaredElements = solution.GetPsiServices() .Symbols.GetSymbolScope(scope.AsLibrarySymbolScope(), true) .GetElementsByQualifiedName(crefText); if (declaredElements.Count == 0) { return crefText; } List<TypeAndNamespace> typesAndNamespaces = getTypeAndNamespaces(declaredElements, declaration, solution, scope); if (typesAndNamespaces.Count > 0) { TypeAndNamespace first = typesAndNamespaces[0]; if (methodName == null) return first.XmlDocId; IClass cls = first.TypeElement as IClass; if (cls != null && cls.Methods.Count(x => x.ShortName == methodName) == 1) { return string.Format("{0}.{1}", first.XmlDocId, methodName); } return string.Format("{0}.{1}{2}", first.XmlDocId, methodName, methodArgs); } return crefText; }