public static string GetPropertyTypeName(TransportModelEntityMember member, Settings settings, ModelType modelType, bool useSimpleCollections = false)
        {
            if (member.IsNullable &&
                member.Type is TransportModelTypeReferencePrimitive primitiveReference &&
                primitiveReference.PrimitiveType != TransportModelPrimitiveType.String &&
                primitiveReference.PrimitiveType != TransportModelPrimitiveType.Object &&
                !member.Type.IsCollection)
            {
                var name = CreateModelPrimitiveTypeName(primitiveReference, settings, modelType);

                return(WrapTypeNameWithNullable(name));
            }

            var result = GetCSharpModelReferenceName(member.Type, settings, modelType, useSimpleCollections);

            if (member.Type is ITransportModelTypeReferenceTransportModelItem <TransportModelItem> itemReference &&
                itemReference.TransportModelItem is TransportModelEnum &&
                member.IsNullable &&
                !member.Type.IsCollection)
            {
                result = WrapTypeNameWithNullable(result);
            }

            return(result);
        }
        public static string GetAstModelPropertyTypeName(TransportModelEntityMember member, Settings settings, bool useSimpleCollections = false)
        {
            if (member.Type is ITransportModelTypeReferenceTransportModelItem <TransportModelItem> itemReference && itemReference.TransportModelItem is TransportModelEnum)
            {
                var result = CreateModelTypeName(itemReference, settings, ModelType.Transport, useSimpleCollections);
                if (member.IsNullable &&
                    !member.Type.IsCollection)
                {
                    result = WrapTypeNameWithNullable(result);
                }

                return(result);
            }
            else
            {
                return(GetPropertyTypeName(member, settings, ModelType.Ast, useSimpleCollections));
            }
        }
        private MemberDeclarationSyntax CreatePropertyDeclaration(TransportModelEntityMember member)
        {
            if (CsEmitterHelper.IsNode(member.Type))
            {
                if (member.Type.IsCollection)
                {
                    return(PropertyDeclaration(ParseTypeName(CsEmitterHelper.GetAstModelPropertyTypeName(member, this.settings)), NameHelper.GetSafeVariableName(member.Name))
                           .WithAccessorList(
                               SyntaxFactory.AccessorList(
                                   SyntaxFactory.List <AccessorDeclarationSyntax>(new AccessorDeclarationSyntax[]
                    {
                        SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                        .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
                        SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                        .WithModifiers(TokenList(CsEmitterHelper.IsNodeCollection(member.Type) ? new [] { Token(SyntaxKind.PrivateKeyword) } : new SyntaxToken[0]))
                        .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
                    })))
                           .AddModifiers(Token(SyntaxKind.PublicKeyword)));
                }
                else
                {
                    return(PropertyDeclaration(ParseTypeName(CsEmitterHelper.GetAstModelPropertyTypeName(member, this.settings)), NameHelper.GetSafeVariableName(member.Name))
                           .WithAccessorList(
                               SyntaxFactory.AccessorList(
                                   SyntaxFactory.List <AccessorDeclarationSyntax>(new AccessorDeclarationSyntax[]
                    {
                        SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                        .WithBody(Block(List <StatementSyntax>(new [] { ReturnStatement(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(this.GetFieldName(member.Name)))) }))),
                        SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                        .WithBody(
                            Block(
                                List <StatementSyntax>(new []
                        {
                            ExpressionStatement(
                                InvocationExpression(
                                    MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName("SetAsParentFor")),
                                    ArgumentList(SeparatedList <ArgumentSyntax>(new []
                            {
                                Argument(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(this.GetFieldName(member.Name)))),
                                Argument(IdentifierName("value"))
                            })))),
                            ExpressionStatement(
                                AssignmentExpression(
                                    SyntaxKind.SimpleAssignmentExpression,
                                    MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(this.GetFieldName(member.Name))),
                                    IdentifierName("value")))
                        })))
                    })))
                           .AddModifiers(Token(SyntaxKind.PublicKeyword)));
                }
            }
            else
            {
                if (member.Type.IsCollection)
                {
                    throw new InvalidOperationException("Non-node collections are not supported yet.");
                }

                return(PropertyDeclaration(ParseTypeName(CsEmitterHelper.GetAstModelPropertyTypeName(member, this.settings)), NameHelper.GetSafeVariableName(member.Name))
                       .WithAccessorList(
                           SyntaxFactory.AccessorList(
                               SyntaxFactory.List <AccessorDeclarationSyntax>(new AccessorDeclarationSyntax[]
                {
                    SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                    .WithBody(Block(List <StatementSyntax>(new [] { ReturnStatement(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(this.GetFieldName(member.Name)))) }))),
                    SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                    .WithBody(
                        Block(
                            List <StatementSyntax>(new []
                    {
                        ExpressionStatement(
                            InvocationExpression(
                                MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName("EnsureIsEditable")),
                                ArgumentList(SeparatedList <ArgumentSyntax>()))),
                        ExpressionStatement(
                            AssignmentExpression(
                                SyntaxKind.SimpleAssignmentExpression,
                                MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpression(), IdentifierName(this.GetFieldName(member.Name))),
                                IdentifierName("value")))
                    })))
                })))
                       .AddModifiers(Token(SyntaxKind.PublicKeyword)));
            }
        }