コード例 #1
0
 public CSharpSyntaxNode Find(CSharpSyntaxNode root)
 {
     return((MethodNodeFinder.Find(root) as MethodDeclarationSyntax)
            .ParameterList
            .Parameters
            .FirstOrDefault(n => n.Identifier.Text == Name));
 }
コード例 #2
0
        private static async Task <IEnumerable <ISyntaxNodeFinder> > GetItemsForTransform(Project project, Compilation compilation, Document doc)
        {
            var nodeFinders = new List <ISyntaxNodeFinder>();

            var root = await doc.GetSyntaxRootAsync();

            var model = compilation.GetSemanticModel(root.SyntaxTree);

            foreach (var classDeclaration in root.DescendantNodesAndSelf().OfType <ClassDeclarationSyntax>())
            {
                var classNodeFinder = new ClassNodeFinder(classDeclaration.Identifier.Text);

                var publicMembers = classDeclaration.Members.Where(m => m.Modifiers.Any(mm => mm.Text == "public"));

                foreach (var member in publicMembers)
                {
                    if (member is MethodDeclarationSyntax methodDelcaration)
                    {
                        var methodNodeFinder = new MethodNodeFinder(classNodeFinder, methodDelcaration.Identifier.Text);

                        foreach (var parameter in methodDelcaration?.ParameterList?.Parameters)
                        {
                            if (ShouldBeTransformed(parameter.Identifier.Text))
                            {
                                var parameterNodeFinder = new MethodParameterNodeFinder(methodNodeFinder, parameter.Identifier.Text);
                                nodeFinders.Add(parameterNodeFinder);
                            }
                        }

                        if (ShouldBeTransformed(methodDelcaration.Identifier.Text))
                        {
                            nodeFinders.Add(methodNodeFinder);
                        }
                    }
                    else if (member is PropertyDeclarationSyntax propertyDeclaration)
                    {
                        if (ShouldBeTransformed(propertyDeclaration.Identifier.Text))
                        {
                            var propertyNodeFinder = new PropertyNodeFinder(classNodeFinder, propertyDeclaration.Identifier.Text);
                            nodeFinders.Add(propertyNodeFinder);
                        }
                    }
                    else if (member is FieldDeclarationSyntax fieldDeclaration)
                    {
                        foreach (var variableNode in fieldDeclaration.Declaration.Variables)
                        {
                            if (ShouldBeTransformed(variableNode.Identifier.Text))
                            {
                                var fieldNodeFinder = new FieldNodeFinder(classNodeFinder, variableNode.Identifier.Text);
                                nodeFinders.Add(fieldNodeFinder);
                            }
                        }
                    }
                }
            }

            return(nodeFinders);
        }
コード例 #3
0
 public MethodParameterNodeFinder(MethodNodeFinder methodNodeFinder, string name)
 {
     MethodNodeFinder = methodNodeFinder;
     Name             = name;
 }