Exemplo n.º 1
0
        private static async Task RunAsync()
        {
            var solution = await MSBuildWorkspace.Create().OpenSolutionAsync(
                @"D:\Developments\Open\MSTestEnhancer\MSTest.Extensions.sln");

            var project  = solution.Projects.First(x => x.Name == "MSTest.Extensions");
            var document = project.Documents.First(x =>
                                                   x.Name.Equals("ContractTestContext.cs", StringComparison.InvariantCultureIgnoreCase));

            var tree = await document.GetSyntaxTreeAsync();

            var syntax = tree.GetCompilationUnitRoot();

            var visitor = new TypeParameterVisitor();
            var node    = visitor.Visit(syntax);

            var text = node.GetText();

            File.WriteAllText(document.FilePath, text.ToString());
        }
Exemplo n.º 2
0
        //"ACTAnimConfig"
        MethodDeclarationSyntax FindFuncAsync(SyntaxTree tree, string type, string func)
        {
            var syntax = tree.GetCompilationUnitRoot();

            TypeParameterVisitor visitor = new TypeParameterVisitor(type);
            SyntaxNode           node    = visitor.Visit(syntax);

            if (visitor.typeDecl1 != null)
            {
                foreach (MemberDeclarationSyntax member in visitor.typeDecl1.Members)
                {
                    if (member is MethodDeclarationSyntax)
                    {
                        MethodDeclarationSyntax ed = member as MethodDeclarationSyntax;
                        if (ed.Identifier.Text == func)
                        {
                            return(ed);
                        }
                    }
                }
            }
            return(null);
        }