private static IEnumerable <MethodDeclarationSyntax> GenerateApiControllerMethods(IEnumerable <MethodDeclarationSyntax> grainInterfaceMethods, string grainName)
        {
            var methodsDeclarations = new List <MethodDeclarationSyntax>();

            foreach (var methodNode in grainInterfaceMethods)
            {
                // insert the id parameter at the end of the list of parameters
                var idParam = RoslynUtils.CreateParameter("string", "id");
                MethodDeclarationSyntax methodDclr = RoslynUtils.AppendParameterToMethod(methodNode, idParam);

                methodDclr = methodDclr.AddModifiers(SF.Token(SyntaxKind.PublicKeyword)).WithSemicolonToken(SF.Token(SyntaxKind.None));

                StatementSyntax getGrainStmt = SF.ParseStatement(string.Format(
                                                                     "var grain = _grainFactory.GetGrain<{0}>(id);\n", grainName));
                MethodInspector methodInspector = new MethodInspector(methodNode);

                string callGrainStmt = string.Format("grain.{0}({1});",
                                                     methodInspector.MethodName, string.Join(", ", methodInspector.MethodParams.Keys));

                if (methodInspector.ReturnType != "Task")
                {
                    callGrainStmt = callGrainStmt.Insert(0, "return ");
                }
                else
                {
                    callGrainStmt = callGrainStmt.Insert(0, "await ");
                    methodDclr    = methodDclr.AddModifiers(SF.Token(SyntaxKind.AsyncKeyword));
                }
                StatementSyntax returnStmt = SF.ParseStatement(callGrainStmt);

                methodsDeclarations.Add(methodDclr.WithBody(SF.Block(getGrainStmt, returnStmt)));
            }
            return(methodsDeclarations);
        }
Пример #2
0
        public static MethodDeclarationSyntax CreateMethod(MethodGenerationData data)
        {
            Debug.Assert(!string.IsNullOrEmpty(data.m_MethodName), "Trying to generate a method with null or empty method name!");
            Debug.Assert(!string.IsNullOrEmpty(data.m_MethodReturnType), "Trying to generate a method with null or empty return type!");
            Debug.Assert(data.m_MethodBodyStatements != null && data.m_MethodBodyStatements.Count > 0, "Trying to generate a method with no body!");

            MethodDeclarationSyntax syntax = SyntaxFactory
                                             .MethodDeclaration(SyntaxFactory.ParseTypeName(data.m_MethodReturnType), data.m_MethodName)
                                             .AddModifiers(CodeGenerationUtility.CreateProtectionLevelToken(data.m_ProtectionLevel));

            switch (data.m_InheritanceKeyword)
            {
            case FunctionInheritanceKeyword.STATIC: syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword)); break;

            case FunctionInheritanceKeyword.OVERRIDE: syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.OverrideKeyword)); break;

            case FunctionInheritanceKeyword.VIRTUAL: syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.VirtualKeyword)); break;
            }

            if (data.m_IsAsync)
            {
                bool canMakeAsync = false;

                for (int i = 0; i < s_AcceptedAsyncReturnTypes.Length; i++)
                {
                    if (!data.m_MethodReturnType.Contains(s_AcceptedAsyncReturnTypes[i]))
                    {
                        continue;
                    }

                    canMakeAsync = true;
                    break;
                }

                Debug.Assert(canMakeAsync, "Trying to generate async function but the return type is not supported! Please make the return type either void, Task or UniTask");

                if (canMakeAsync)
                {
                    syntax = syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.AsyncKeyword));
                }
            }

            syntax = syntax.AddAttributeLists(AttributeGenerationService.CreateAttributeListSyntaxes(data.m_Attributes));

            foreach (var param in data.m_MethodParams)
            {
                syntax = syntax.AddParameterListParameters(CodeGenerationUtility.CreateParameterSyntax(param.m_ParamName, param.m_ParamType));
            }

            foreach (var statement in data.m_MethodBodyStatements)
            {
                syntax = syntax.AddBodyStatements((SyntaxFactory.ParseStatement(statement)));
            }

            return(syntax);
        }
Пример #3
0
            public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
            {
                if (node.Parent is not ClassDeclarationSyntax classDeclaration)
                {
                    return(node);
                }

                // Note: this won't work if the method is in one part of a partial class and only the other part has the sealed modifier
                if (classDeclaration.Modifiers.Any(SealedKeyword))
                {
                    return(node);
                }

                var modifiers = node.Modifiers;

                var forbiddenModifiers = new[] { StaticKeyword, SealedKeyword, VirtualKeyword, OverrideKeyword };
                var requiredModifiers  = new[] { PublicKeyword, ProtectedKeyword, InternalKeyword };

                if (forbiddenModifiers.Any(modifier => node.Modifiers.Any(modifier)) ||
                    !requiredModifiers.Any(modifier => node.Modifiers.Any(modifier)))
                {
                    return(node);
                }

                return(node.AddModifiers(SyntaxFactory.Token(VirtualKeyword)));
            }
Пример #4
0
        private static MethodDeclarationSyntax MemberFunctionModifiers(MethodDeclarationSyntax method)
        {
            var modifiers = method.Modifiers;

            if (!modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword)))
            {
                method = method.AddModifiers(CSharp.Token(SyntaxKind.StaticKeyword));
            }

            if (!Roslyn.HasVisibilityModifier(method.Modifiers))
            {
                method = method.AddModifiers(CSharp.Token(SyntaxKind.PublicKeyword));
            }

            return(method);
        }
Пример #5
0
        private void GenerateIBuildsInterfaceImplementation(ClassGenerator @class)
        {
            @class.AddBaseType(GenericName("IBuilds").AddTypeArgumentListArguments(NameSyntax));

            MethodDeclarationSyntax buildMethod = MethodDeclaration(returnType: NameSyntax, Identifier("Build"))
                                                  .AddModifiers(Token(SyntaxKind.PublicKeyword))
                                                  .AddBodyStatements(
                ReturnStatement(
                    ObjectCreationExpression(NameSyntax)
                    .AddArgumentListArguments(Argument(ThisExpression()))));

            ConversionOperatorDeclarationSyntax implicitCastOperator =
                ConversionOperatorDeclaration(Token(SyntaxKind.ImplicitKeyword), NameSyntax)
                .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword))
                .AddParameterListParameters(
                    Parameter(Identifier("builder"))
                    .WithType(IdentifierName(BuilderClassName)))
                .AddBodyStatements(
                    ReturnStatement(
                        InvocationExpression(
                            MemberAccessExpression(
                                SyntaxKind.SimpleMemberAccessExpression,
                                IdentifierName("builder"),
                                IdentifierName("Build")))));

            if (BaseClass != null)
            {
                buildMethod = buildMethod.AddModifiers(Token(SyntaxKind.NewKeyword));
            }

            @class.AddMembers(buildMethod, implicitCastOperator);
        }
Пример #6
0
        /// <summary>
        /// Initializing of visitor
        /// </summary>
        public RoslynTreeBuilderVisitor(string libraryModuleName = null)
        {
            //Create unit
            unitNode = CompilationUnit();

            //Create public class "Program" (or library unit's name)
            this.libraryModuleName = libraryModuleName;
            string className = libraryModuleName ?? "$Program";

            programClassNode = ClassDeclaration(className).AddModifiers(Token(SyntaxKind.PublicKeyword));

            //Create method void Main()
            mainMethodNode = MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), "Main");

            //Set Main method as static
            mainMethodNode = mainMethodNode.AddModifiers(Token(SyntaxKind.StaticKeyword));

            //Add to Main method empty body
            mainMethodNode = mainMethodNode.AddBodyStatements();

            //Set Main method as current block (push to stack)
            blocks.Push(mainMethodNode);

            //initialize dictionary of location annotations
            LocationAnnotations = new List <SyntaxAnnotation>();
        }
Пример #7
0
 public static MethodDeclarationSyntax AddModifiers(this MethodDeclarationSyntax cl, params SyntaxKind[] modifiers)
 {
     if (modifiers == null)
     {
         return(cl);
     }
     return(cl.AddModifiers(modifiers.Select(x => SyntaxFactory.Token(x)).ToArray()));
 }
Пример #8
0
 public static MethodDeclarationSyntax WithStatic(this MethodDeclarationSyntax syntax, bool isStatic)
 {
     if (isStatic)
     {
         return(syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword)));
     }
     else
     {
         return(syntax.WithModifiers(SyntaxFactory.TokenList()));
     }
 }
Пример #9
0
        private MethodDeclarationSyntax CreateTestMethod(string methodName)
        {
            AttributeListSyntax attributes = SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(
                                                                             SyntaxFactory.Attribute(SyntaxFactory.IdentifierName("TestMethod")))
                                                                         ).NormalizeWhitespace();

            MethodDeclarationSyntax testMethod = SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName("void"), "Test" + methodName);

            testMethod = testMethod.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)).AddAttributeLists(attributes).AddBodyStatements(SyntaxFactory.ParseStatement("Assert.Fail(\"autogenerated\");"));
            return(testMethod);
        }
Пример #10
0
        private static Solution UpdateMainDocument(Document document, SyntaxNode root, MethodDeclarationSyntax method, IEnumerable <IGrouping <Document, ReferenceLocation> > documentGroups)
        {
            var        mainDocGroup = documentGroups.FirstOrDefault(dg => dg.Key.Equals(document));
            SyntaxNode newRoot;

            if (mainDocGroup == null)
            {
                newRoot = root.ReplaceNode(method, method.AddModifiers(staticToken));
            }
            else
            {
                var diagnosticNodes = mainDocGroup.Select(referenceLocation => root.FindNode(referenceLocation.Location.SourceSpan)).ToList();
                newRoot = root.TrackNodes(diagnosticNodes.Union(new[] { method }));
                newRoot = newRoot.ReplaceNode(newRoot.GetCurrentNode(method), method.AddModifiers(staticToken));
                foreach (var diagnosticNode in diagnosticNodes)
                {
                    var token       = newRoot.FindToken(diagnosticNode.GetLocation().SourceSpan.Start);
                    var tokenParent = token.Parent;
                    if (token.Parent.IsKind(SyntaxKind.IdentifierName))
                    {
                        continue;
                    }
                    var invocationExpression = newRoot.GetCurrentNode(diagnosticNode).FirstAncestorOrSelfOfType <InvocationExpressionSyntax>()?.Expression;
                    if (invocationExpression == null || invocationExpression.IsKind(SyntaxKind.IdentifierName))
                    {
                        continue;
                    }
                    var memberAccess = invocationExpression as MemberAccessExpressionSyntax;
                    if (memberAccess == null)
                    {
                        continue;
                    }
                    var newMemberAccessParent = memberAccess.Parent.ReplaceNode(memberAccess, memberAccess.Name)
                                                .WithAdditionalAnnotations(Formatter.Annotation);
                    newRoot = newRoot.ReplaceNode(memberAccess.Parent, newMemberAccessParent);
                }
            }
            var newSolution = document.Project.Solution.WithDocumentSyntaxRoot(document.Id, newRoot);

            return(newSolution);
        }
Пример #11
0
        private static SyntaxNode ConvertMethodToAsync(MethodDeclarationSyntax methodNode)
        {
            var token         = methodNode.GetFirstToken();
            var leadingTrivia = TriviaList();

            if (methodNode.ReturnType.GetFirstToken() == token)
            {
                methodNode    = methodNode.ReplaceToken(token, token.WithLeadingTrivia(leadingTrivia));
                leadingTrivia = token.LeadingTrivia;
            }
            return(methodNode
                   .AddModifiers(Token(leadingTrivia, SyntaxKind.AsyncKeyword, TriviaList(Space)))
                   .WithAdditionalAnnotations(Formatter.Annotation));
        }
        public MemberDeclarationSyntax Generate(ILocatedOpenApiElement <OpenApiOperation> operation,
                                                ILocatedOpenApiElement <OpenApiMediaType>?mediaType)
        {
            MethodDeclarationSyntax methodDeclaration = GenerateHeader(operation);

            if (mediaType == null)
            {
                // In the base request class which has no body
                methodDeclaration = methodDeclaration
                                    .AddModifiers(Token(SyntaxKind.ProtectedKeyword), Token(SyntaxKind.VirtualKeyword))
                                    .WithExpressionBody(ArrowExpressionClause(
                                                            LiteralExpression(SyntaxKind.NullLiteralExpression)));
            }
            else
            {
                // In an inherited request class which adds a body
                methodDeclaration = methodDeclaration
                                    .AddModifiers(Token(SyntaxKind.ProtectedKeyword), Token(SyntaxKind.OverrideKeyword))
                                    .WithBody(Block(GenerateStatements(operation, mediaType)));
            }

            return(methodDeclaration);
        }
        private MethodDeclarationSyntax CreateFunctionDeclaration(FunctionDeclaration node)
        {
            MethodDeclarationSyntax methodDeclaration = SyntaxFactory.MethodDeclaration(node.Type.ToCsNode <TypeSyntax>(), node.Name.Text);

            methodDeclaration = methodDeclaration.AddModifiers(node.Modifiers.ToCsNodes <SyntaxToken>());
            methodDeclaration = methodDeclaration.AddParameterListParameters(node.Parameters.ToCsNodes <ParameterSyntax>());

            if (node.JsDoc.Count > 0)
            {
                methodDeclaration = methodDeclaration.WithLeadingTrivia(SyntaxFactory.Trivia(node.JsDoc[0].ToCsNode <DocumentationCommentTriviaSyntax>()));
            }
            if (node.TypeParameters.Count > 0)
            {
                methodDeclaration = methodDeclaration.AddTypeParameterListParameters(node.TypeParameters.ToCsNodes <TypeParameterSyntax>());
            }

            return(methodDeclaration.WithBody(node.Body.ToCsNode <BlockSyntax>()));
        }
Пример #14
0
        private static MethodDeclarationSyntax singletonPublicSignal(MethodDeclarationSyntax method, out MethodDeclarationSyntax result)
        {
            result = method.WithIdentifier(CSharp.ParseToken("__" + method.Identifier.ToString()));

            var sCall = method.ReturnType.ToString() == "void"
                ? Templates.SingletonCall
                        .Get <StatementSyntax>(result.Identifier.ToString())
                : Templates.SingletonReturnCall
                        .Get <StatementSyntax>(result.Identifier.ToString());

            return(method
                   .AddModifiers([email protected]())
                   .WithBody(CSharp.Block(sCall
                                          .ReplaceNodes(sCall
                                                        .DescendantNodes()
                                                        .OfType <ArgumentListSyntax>(),
                                                        (on, nn) => nn.WithArguments(CSharp.SeparatedList(method
                                                                                                          .ParameterList
                                                                                                          .Parameters
                                                                                                          .Select(parameter => CSharp.Argument(CSharp.IdentifierName(parameter.Identifier)))))))));
        }
Пример #15
0
        private MethodDeclarationSyntax CreateMethodDeclaration(IAnonymousFunctionOperation operation,
                                                                IFieldSymbol fieldSymbol,
                                                                BlockSyntax block, ArrowExpressionClauseSyntax arrow)
        {
            MethodDeclarationSyntax methodDecl =
                ((MethodDeclarationSyntax)CommonConversions.CsSyntaxGenerator.MethodDeclaration(operation.Symbol))
                .WithIdentifier(SyntaxFactory.Identifier(fieldSymbol.Name))
                .WithBody(block).WithExpressionBody(arrow);

            if (operation.Symbol.IsAsync)
            {
                methodDecl = methodDecl.AddModifiers(SyntaxFactory.Token(SyntaxKind.AsyncKeyword));
            }

            if (arrow != null)
            {
                methodDecl = methodDecl.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
            }

            return(methodDecl);
        }
Пример #16
0
        public static void AddMacro(MethodDeclarationSyntax macro, string namespaceName, string className)
        {
            string methodName = macro.Identifier.ToString();

            var assemblies = new[]
            {
                typeof(SyntaxNode).GetTypeInfo().Assembly.Location,
                typeof(SyntaxFactory).GetTypeInfo().Assembly.Location,
            };

            var program = MacroCompilationUnit
                          .AddMembers(NamespaceDeclaration(IdentifierName(namespaceName))
                                      .AddMembers(ClassDeclaration(className)
                                                  .AddMembers(macro
                                                              .AddModifiers(new[] { Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword) }))));

            MacroStore[methodName] = new Lazy <MethodInfo>(() =>
            {
                var stream    = Compiler.Compile(namespaceName, assemblies, OutputType.DynamicallyLinkedLibrary, program);
                var macroFunc = AssemblyRunner.GetFunction(stream, namespaceName, className, methodName);
                return(macroFunc);
            });
        }
Пример #17
0
 public static MethodDeclarationSyntax AddModifiers(this MethodDeclarationSyntax syntax, params SyntaxKind[] modifier)
 {
     return(syntax.AddModifiers(modifier.Select(Token).ToArray()));
 }
        public void Generate()
        {
            // standard using directives
            CompilationUnitSyntax cu = SyntaxFactory.CompilationUnit()
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Collections.Generic")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Linq")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Text")))
                                       .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System.Threading.Tasks")));

            NamespaceDeclarationSyntax localNamespace = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.IdentifierName(directoryName));

            ClassDeclarationSyntax localClass = SyntaxFactory.ClassDeclaration(Name);

            foreach (var member in Declarations)
            {
                switch (member.DeclarationType)
                {
                case "method":
                    var currentMethod = member as Method;

                    //currentMethod.Type is a string parsed from the uml diagram
                    MethodDeclarationSyntax method = SyntaxFactory.MethodDeclaration(SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(currentMethod.Type)), currentMethod.Name);

                    List <SyntaxToken> mods = new List <SyntaxToken>();

                    foreach (var modifier in currentMethod.Modifiers)
                    {
                        mods.Add(SyntaxFactory.ParseToken(modifier));
                    }

                    method = method.AddModifiers(mods.ToArray());

                    SeparatedSyntaxList <ParameterSyntax> ssl = SyntaxFactory.SeparatedList <ParameterSyntax>();
                    foreach (var param in currentMethod.Arguments)
                    {
                        ParameterSyntax ps = SyntaxFactory.Parameter(
                            new SyntaxList <AttributeListSyntax>(),
                            new SyntaxTokenList(),
                            SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(param.Type)),
                            SyntaxFactory.Identifier(param.Name), null);

                        ssl = ssl.Add(ps);
                    }

                    method = method.AddParameterListParameters(ssl.ToArray());

                    // we add an exception to the body of an otherwise empty method
                    ThrowStatementSyntax notReady = SyntaxFactory.ThrowStatement(SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName("NotImplementedException"), SyntaxFactory.ArgumentList(), null));

                    method = method.AddBodyStatements(notReady);

                    localClass = localClass.AddMembers(method);
                    break;

                case "field":
                    var currentField = member as Field;

                    SyntaxTokenList stl = new SyntaxTokenList();

                    foreach (var modifier in currentField.Modifiers)
                    {
                        stl = stl.Add(SyntaxFactory.ParseToken(modifier));
                    }

                    SeparatedSyntaxList <VariableDeclaratorSyntax> svd = SyntaxFactory.SeparatedList <VariableDeclaratorSyntax>();

                    svd = svd.Add(SyntaxFactory.VariableDeclarator(currentField.Name));

                    // currentField.Type is a string parsed from the uml diagram
                    VariableDeclarationSyntax variable = SyntaxFactory.VariableDeclaration(SyntaxFactory.ParseTypeName(currentField.Type), svd);

                    FieldDeclarationSyntax field = SyntaxFactory.FieldDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        stl,
                        variable
                        );

                    localClass = localClass.AddMembers(field);
                    break;
                }
            }

            localNamespace = localNamespace.AddMembers(localClass);
            cu             = cu.AddMembers(localNamespace);

            AdhocWorkspace cw      = new AdhocWorkspace();
            OptionSet      options = cw.Options;

            cw.Options.WithChangedOption(CSharpFormattingOptions.IndentBraces, true);
            SyntaxNode formattedNode = Formatter.Format(cu, cw, options);

            formattedNode.WriteTo(writer);
        }
Пример #19
0
        private IEnumerable <MemberDeclarationSyntax> getMembers(Type type, TypeNameResolver typeNameResolver)
        {
            // TODO: Add static members to a manager interface. (Daniel Potter, 11/8/2017)
            foreach (MemberInfo memberInfo in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                if (memberInfo.GetCustomAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)) != null)
                {
                    continue;
                }

                MemberExtensionKind extensionKind;
                switch (memberInfo.MemberType)
                {
                case MemberTypes.Constructor:
                    // TODO: Constructors should be added to a manager interface. (Daniel
                    //       Potter, 11/8/2017)
                    break;

                case MemberTypes.Event:
                    var eventInfo = (EventInfo)memberInfo;

                    extensionKind = eventInfo.GetExtensionKind();
                    if (extensionKind == MemberExtensionKind.Override)
                    {
                        continue;
                    }

                    EventFieldDeclarationSyntax eventDeclaration = getEvent(eventInfo, typeNameResolver);

                    if (extensionKind == MemberExtensionKind.New)
                    {
                        eventDeclaration = eventDeclaration
                                           .AddModifiers(Token(SyntaxKind.NewKeyword));
                    }

                    yield return(eventDeclaration);

                    break;

                case MemberTypes.Field:
                    // TODO: Constants need to be handled somehow. (Daniel Potter, 11/8/2017)
                    break;

                case MemberTypes.Method:
                    var methodInfo = (MethodInfo)memberInfo;

                    if (methodInfo.IsSpecialName)
                    {
                        continue;
                    }

                    extensionKind = methodInfo.GetExtensionKind();
                    if (extensionKind == MemberExtensionKind.Override)
                    {
                        continue;
                    }

                    MethodDeclarationSyntax methodDeclaration = getMethod(methodInfo, typeNameResolver);

                    if (extensionKind == MemberExtensionKind.New)
                    {
                        methodDeclaration = methodDeclaration
                                            .AddModifiers(Token(SyntaxKind.NewKeyword));
                    }

                    yield return(methodDeclaration);

                    break;

                case MemberTypes.Property:
                    var propertyInfo = (PropertyInfo)memberInfo;

                    extensionKind = propertyInfo.GetExtensionKind();
                    if (extensionKind == MemberExtensionKind.Override)
                    {
                        continue;
                    }

                    if (propertyInfo.GetIndexParameters().Length > 0)
                    {
                        IndexerDeclarationSyntax indexerDeclaration = getIndexer(propertyInfo, typeNameResolver);

                        if (extensionKind == MemberExtensionKind.New)
                        {
                            indexerDeclaration = indexerDeclaration
                                                 .AddModifiers(Token(SyntaxKind.NewKeyword));
                        }

                        yield return(indexerDeclaration);
                    }
                    else
                    {
                        PropertyDeclarationSyntax propertyDeclaration = getProperty(propertyInfo, typeNameResolver);

                        if (extensionKind == MemberExtensionKind.New)
                        {
                            propertyDeclaration = propertyDeclaration
                                                  .AddModifiers(Token(SyntaxKind.NewKeyword));
                        }

                        yield return(propertyDeclaration);
                    }
                    break;

                case MemberTypes.NestedType:
                    // TODO: Nested types need to be handled somehow. (Daniel Potter, 11/8/2017)
                    break;

                default:
                    // TODO: Log these for diagnostics. (Daniel Potter, 11/8/2017)
                    break;
                }
            }
        }
Пример #20
0
 public static MethodDeclarationSyntax WithPublicModifier(this MethodDeclarationSyntax method)
 => method.AddModifiers(Token(SyntaxKind.PublicKeyword));
Пример #21
0
 public static MethodDeclarationSyntax WithModifiers(this MethodDeclarationSyntax node, params SyntaxKind[] modifiers)
 {
     return(node.AddModifiers(CreateModifiers(modifiers)));
 }
Пример #22
0
 public static MethodDeclarationSyntax WithStatic(this MethodDeclarationSyntax syntax, bool isStatic)
 => isStatic?syntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword))
     : syntax.WithModifiers(SyntaxFactory.TokenList());
 private static Task <Document> FixMissingStatic(Document contextDocument, SyntaxNode root, MethodDeclarationSyntax method)
 {
     return(Task.FromResult(contextDocument.WithSyntaxRoot(root.ReplaceNode(method, method.AddModifiers(Token(SyntaxKind.StaticKeyword))))));
 }
Пример #24
0
 public static MethodDeclarationSyntax AsVirtual(this MethodDeclarationSyntax methodDeclarationSyntax)
 {
     return(methodDeclarationSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.VirtualKeyword)));
 }