Exemple #1
0
        private static IEnumerable <MemberDeclarationSyntax> createRemoteConstructors(ClassDeclarationSyntax @class, string typeName)
        {
            var constructor = @class
                              .ChildNodes()
                              .OfType <ConstructorDeclarationSyntax>()
                              .OrderBy(ctor => ctor.ParameterList.Parameters.Count)
                              .FirstOrDefault();

            var result = CSharp.ConstructorDeclaration(typeName)
                         .AddParameterListParameters(CSharp
                                                     .Parameter(CSharp.Identifier("id")).WithType(CSharp.ParseTypeName("Guid")))
                         .WithBody(CSharp.Block(Templates.RemoteIdAssign))
                         .WithModifiers(Roslyn.@public);

            if (constructor != null)
            {
                result = result.WithInitializer(CSharp.ConstructorInitializer(
                                                    SyntaxKind.BaseConstructorInitializer,
                                                    CSharp.ArgumentList(CSharp.SeparatedList(
                                                                            constructor
                                                                            .ParameterList
                                                                            .Parameters
                                                                            .Select(parameter => CSharp.Argument(
                                                                                        CSharp.DefaultExpression(parameter.Type)))))));
            }

            return(new MemberDeclarationSyntax[]
            {
                result
            });
        }