Exemplo n.º 1
0
        public static IEnumerable <T> GetAllSyntaxNodesFromFile <T>(string filePath) where T : SyntaxNode
        {
            if (!_cacheAllSyntaxNodesFromFile.ContainsKey(filePath))
            {
                var source   = TextFileReader.ReadFile(filePath);
                var document = DocumentProvider.CreateDocument(source);

                var root  = document.GetSyntaxRootAsync().Result;
                var nodes = root.DescendantNodes().OfType <T>().ToList();
                _cacheAllSyntaxNodesFromFile.TryAdd(filePath, nodes);
            }

            return(_cacheAllSyntaxNodesFromFile[filePath].Select(_ => _ as T));
        }
Exemplo n.º 2
0
        public static T GetSyntaxNodeFromFile <T>(string filePath, string syntaxIdentifier) where T : SyntaxNode
        {
            var key = filePath + syntaxIdentifier;

            if (!_cacheSyntaxNodeFromFile.ContainsKey(key))
            {
                var source   = TextFileReader.ReadFile(filePath);
                var document = DocumentProvider.CreateDocument(source);

                var root = document.GetSyntaxRootAsync().Result;
                var node = root.DescendantNodesAndSelf().OfType <T>().First(_ => _.ChildTokens().Any(t => t.IsKind(SyntaxKind.IdentifierToken) && t.Text == syntaxIdentifier));

                _cacheSyntaxNodeFromFile.TryAdd(key, node);
            }

            return(_cacheSyntaxNodeFromFile[key] as T);
        }
Exemplo n.º 3
0
        public SyntaxGenerator GetSyntaxGenerator(string source)
        {
            var document = DocumentProvider.CreateDocument(source);

            return(SyntaxGenerator.GetGenerator(document));
        }