コード例 #1
0
 public static AttributeListSyntax GenAttribute(string name, string args)
 {
     return(SF.AttributeList(
                SF.SingletonSeparatedList(
                    SF.Attribute(
                        SF.IdentifierName(name)).WithArgumentList(
                        SF.AttributeArgumentList(
                            SF.SingletonSeparatedList(
                                SF.AttributeArgument(
                                    SF.ParseExpression(args))))))));
 }
コード例 #2
0
ファイル: Utils.cs プロジェクト: suzuke/UnityFixedPoint
 public static SyntaxList <AttributeListSyntax> GenerateStructLayoutAttributes()
 {
     return(SF.SingletonList(
                SF.AttributeList(
                    SF.SingletonSeparatedList(
                        SF.Attribute(SF.IdentifierName("StructLayout"))
                        .WithArgumentList(
                            SF.AttributeArgumentList(
                                SF.SingletonSeparatedList(
                                    SF.AttributeArgument(
                                        SF.MemberAccessExpression(
                                            SK.SimpleMemberAccessExpression,
                                            SF.IdentifierName("LayoutKind"),
                                            SF.IdentifierName("Explicit"))))))))));
 }
コード例 #3
0
ファイル: SyntaxHelper.cs プロジェクト: alexandrvslv/datawf
        public static AttributeSyntax GenAttribute(string name, string args)
        {
            var attribure = SF.Attribute(SF.IdentifierName(name));

            if (args != null)
            {
                attribure = attribure.WithArgumentList(
                    SF.AttributeArgumentList(
                        SF.SingletonSeparatedList(
                            SF.AttributeArgument(
                                SF.ParseExpression(args)))));
            }

            return(attribure);
        }
コード例 #4
0
        private SyntaxList <AttributeListSyntax> CreateSerializationAttribute(SymbolData symbol)
        {
            string requiredValueName;

            if (symbol.IsRequired)
            {
                requiredValueName = (symbol.isNullable) ? "AllowNull" : "Always";
            }
            else
            {
                requiredValueName = "Default";
            }

            Func <string, string, string, AttributeArgumentSyntax> createAttr =
                (lhs, expr, name) =>
            {
                // lhs = expr.name
                return(SF.AttributeArgument(
                           SF.MemberAccessExpression(
                               SyntaxKind.SimpleMemberAccessExpression,
                               SF.IdentifierName(expr),
                               SF.Token(SyntaxKind.DotToken),
                               SF.IdentifierName(name)))
                       .WithNameEquals(
                           SF.NameEquals(SF.IdentifierName(lhs))));
            };

            var attributes = SF.SeparatedList(new[]
            {
                // Required = Required.[requiredValueName]
                createAttr("Required", "Required", requiredValueName),
            });

            if (requiredValueName == "Default" && !symbol.isNullable)
            {
                // NullValueHandling = NullValueHandling.Ignore
                attributes = attributes.Add(
                    createAttr("NullValueHandling", "NullValueHandling", "Ignore"));
            }

            return(SF.SingletonList(
                       SF.AttributeList(
                           SF.SingletonSeparatedList(
                               SF.Attribute(SF.IdentifierName("JsonProperty"))
                               .WithArgumentList(
                                   SF.AttributeArgumentList(attributes))))));
        }
コード例 #5
0
 public static AttributeArgumentListSyntax CreateAttributeArgumentList(params AttributeArgumentSyntax[] attributeArgumentSyntaxs)
 {
     return(SyntaxFactory.AttributeArgumentList(SyntaxFactory.SeparatedList(attributeArgumentSyntaxs)));
 }
コード例 #6
0
ファイル: ControllerBuilder.cs プロジェクト: thewebwolf/MBase
        public static byte[] CreateControllerCode(IService service)
        {
            var @file      = SF.CompilationUnit();
            var @namespace = SF.NamespaceDeclaration(SF.ParseName("MBase.ServiceHost.Controllers")).NormalizeWhitespace();

            @file = @file
                    .AddUsings(SF.UsingDirective(SF.IdentifierName("System")));
            @file = @file
                    .AddUsings(SF.UsingDirective(SF.IdentifierName("Microsoft.AspNetCore.Mvc")));
            @file = @file
                    .AddUsings(SF.UsingDirective(SF.IdentifierName("System.Threading.Tasks")));

            @file = @file.AddUsings(SF.UsingDirective(SF.IdentifierName(service.GetType().Namespace)));
            @file = @file.AddUsings(SF.UsingDirective(SF.IdentifierName(service.GetType().Namespace + ".Models")));

            foreach (var item in service.Commands.Where(m => typeof(ICommand).IsAssignableFrom(m.GetType())))
            {
                @file = @file.AddUsings(SF.UsingDirective(SF.IdentifierName(item.GetType().Namespace)));
            }



            var classDeclaration = SF.ClassDeclaration(service.GetType().Name.ToString() + "Controller")
                                   .AddModifiers(SF.Token(SyntaxKind.PublicKeyword))
                                   .AddBaseListTypes(SF.SimpleBaseType(SF.ParseTypeName("ControllerBase")))
                                   .WithAttributeLists(
                SF.List(
                    new AttributeListSyntax[] {
                SF.AttributeList(
                    SF.SingletonSeparatedList(
                        SF.Attribute(SF.IdentifierName("Route"))
                        .WithArgumentList(
                            SF.AttributeArgumentList(
                                SF.SingletonSeparatedList(
                                    SF.AttributeArgument(
                                        SF.LiteralExpression(SyntaxKind.StringLiteralExpression, SF.Literal($"api/[controller]")))))))),
                SF.AttributeList(
                    SF.SingletonSeparatedList(
                        SF.Attribute(SF.IdentifierName("ApiController"))))
            }));

            List <MemberDeclarationSyntax> controllerMembers = new List <MemberDeclarationSyntax>();

            controllerMembers.Add(
                SF.FieldDeclaration(
                    SF.VariableDeclaration(
                        SF.ParseTypeName(service.GetType().Name))
                    .AddVariables(SF.VariableDeclarator("_service")))
                .AddModifiers(SF.Token(SyntaxKind.PrivateKeyword)));

            controllerMembers.Add(
                SF.ConstructorDeclaration(service.GetType().Name.ToString() + "Controller")
                .WithParameterList(
                    SF.ParameterList(
                        SF.SingletonSeparatedList(
                            SF.Parameter(
                                SF.Identifier("service"))
                            .WithType(
                                SF.IdentifierName("IService")))

                        ))
                .AddModifiers(SF.Token(SyntaxKind.PublicKeyword))
                .WithBody(SF.Block(SF.ParseStatement($"this._service = ({service.GetType().Name})service;"))));

            foreach (var item in service.Commands.Where(m => typeof(ICommand).IsAssignableFrom(m.GetType())))
            {
                var syntax = @$ "

            var response = await CommandHelper.ExecuteMethod<{item.Name}>(new {item.Name}(),new Request<{item.Name}>(request, new MessageEnvelope()));