private static TypeDeclarationSyntax ParseModel(ClassDeclarationSyntax @class, ParameterListSyntax parameters, Scope scope) { var init = new List <ParameterSyntax>(); var props = new List <PropertyDeclarationSyntax>(); foreach (var member in @class.Members) { var field = ParseField(member); if (field == null) { continue; //error has already been registered } var type = field.Declaration.Type; var variable = field.Declaration .Variables .Single(); init.Add(CSharp.Parameter(variable.Identifier) .WithType(type) .WithDefault(CSharp.EqualsValueClause( variable.Initializer != null ? variable.Initializer.Value : CSharp.DefaultExpression(type)))); props.Add(ModelProperty.Get <PropertyDeclarationSyntax>(type) .WithIdentifier(variable.Identifier)); } if (!RoslynCompiler.HasVisibilityModifier(@class.Modifiers)) { @class = @class.AddModifiers(CSharp.Token(SyntaxKind.PublicKeyword)); } return(@class .WithMembers(CSharp.List <MemberDeclarationSyntax>( props.Union(new[] { GenerateConstructor(@class, init) })))); }
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 }); }