Ejemplo n.º 1
0
        public static Document GetDocumentForSymbol(this Compilation compilation, Solution solution, string name)
        {
            var relatedSymbols = compilation.GetSymbolsWithName(p => p == name, SymbolFilter.Type)
                                 .ToList();

            if (relatedSymbols.Count != 1)
            {
                return(null);
            }

            var symbol = relatedSymbols.First() as ITypeSymbol;

            if (symbol.TypeKind == TypeKind.Enum)
            {
                return(null);
            }

            var location = relatedSymbols
                           .Select(p => p.Locations.FirstOrDefault())
                           .FirstOrDefault();

            var docId = solution
                        .GetDocumentIdsWithFilePath(location.SourceTree.FilePath)
                        .FirstOrDefault();

            return(solution.GetDocument(docId));
        }