Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetChildrenFunctionField"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">A description of a foreign key.</param>
        public GetChildrenFunctionField(ForeignElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement;
            this.Name = $"get{this.foreignKeyElement.UniqueChildName}";

            //        /// <summary>
            //        /// Function to get child Buyers.
            //        /// </summary>
            //        private Func<IEnumerable<Buyer>> getBuyers;
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(
                    SyntaxFactory.GenericName(
                        SyntaxFactory.Identifier("Func"))
                    .WithTypeArgumentList(
                        SyntaxFactory.TypeArgumentList(
                            SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                                SyntaxFactory.GenericName(
                                    SyntaxFactory.Identifier("IEnumerable"))
                                .WithTypeArgumentList(
                                    SyntaxFactory.TypeArgumentList(
                                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                                            SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name))))))))
                .WithVariables(
                    SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                        SyntaxFactory.VariableDeclarator(
                            SyntaxFactory.Identifier(this.Name)))))
                          .WithModifiers(GetChildrenFunctionField.Modifiers)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericForeignIndexProperty"/> class.
        /// </summary>
        /// <param name="foreignElement">The column schema.</param>
        public GenericForeignIndexProperty(ForeignElement foreignElement)
        {
            // Initialize the object.
            this.foreignElement = foreignElement;
            this.Name           = this.foreignElement.Name;

            //        /// <summary>
            //        /// Gets the CountryBuyerCountryIdKey foreign index.
            //        /// </summary>
            //        public ForeignIndex<Account, ManagedAccount> AccountManagedAccountIndex { get; private set; }
            this.Syntax = SyntaxFactory.PropertyDeclaration(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("ForeignIndex"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SeparatedList <TypeSyntax>(
                            new SyntaxNodeOrToken[]
            {
                SyntaxFactory.IdentifierName(foreignElement.UniqueKey.Table.Name),
                SyntaxFactory.Token(SyntaxKind.CommaToken),
                SyntaxFactory.IdentifierName(foreignElement.Table.Name),
            }))),
                SyntaxFactory.Identifier(this.Name))
                          .WithModifiers(GenericForeignIndexProperty.Modifiers)
                          .WithAccessorList(GenericForeignIndexProperty.AccessorList)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParentProperty"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The column schema.</param>
        public ParentProperty(ForeignElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement;
            this.Name = this.foreignKeyElement.UniqueParentName;

            //        /// <summary>
            //        /// Gets the parent <see cref="Country"/> record.
            //        /// </summary>
            //        public Country Country { get; }
            this.Syntax = SyntaxFactory.PropertyDeclaration(
                SyntaxFactory.IdentifierName(this.foreignKeyElement.UniqueKey.Table.Name),
                SyntaxFactory.Identifier(this.Name))
                          .WithAccessorList(this.AccessorList)
                          .WithModifiers(ParentProperty.Modifiers)
                          .WithAttributeLists(ParentProperty.Attributes)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultChildrenField"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">A description of a foreign key.</param>
        public DefaultChildrenField(ForeignElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement;
            this.Name = $"Default{this.foreignKeyElement.UniqueChildName}";

            //        /// <summary>
            //        /// Default Buyers.
            //        /// </summary>
            //        private static readonly List<Buyer> defaultBuyers = new List<Buyer>();
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(
                    SyntaxFactory.GenericName(
                        SyntaxFactory.Identifier("List"))
                    .WithTypeArgumentList(
                        SyntaxFactory.TypeArgumentList(
                            SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                                SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name)))))
                .WithVariables(this.Variables))
                          .WithModifiers(DefaultChildrenField.Modifiers)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DictionaryField"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The table schema.</param>
        public DictionaryField(ForeignElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement;

            // This is the name of the field.
            this.Name = "dictionary";

            //        /// <summary>
            //        /// The dictionary containing the index.
            //        /// </summary>
            //        private Dictionary<Guid, ProvinceRow> dictionary = new Dictionary<Guid, ProvinceRow>();
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(this.Type)
                .WithVariables(
                    SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                        SyntaxFactory.VariableDeclarator(
                            SyntaxFactory.Identifier(this.Name))
                        .WithInitializer(this.Initializer))))
                          .WithModifiers(DictionaryField.Modifiers)
                          .WithLeadingTrivia(DictionaryField.DocumentationComment);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ChildrenProperty"/> class.
        /// </summary>
        /// <param name="foreignKeyElement">The column schema.</param>
        public ChildrenProperty(ForeignElement foreignKeyElement)
        {
            // Initialize the object.
            this.foreignKeyElement = foreignKeyElement;
            this.Name = this.foreignKeyElement.UniqueChildName;

            //        /// <summary>
            //        /// Gets the child <see cref="Buyer"/> records.
            //        /// </summary>
            //        public IEnumerable<Buyer> Buyers < Get >
            this.Syntax = SyntaxFactory.PropertyDeclaration(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("IEnumerable"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                            SyntaxFactory.IdentifierName(this.foreignKeyElement.Table.Name)))),
                SyntaxFactory.Identifier(this.Name))
                          .WithAccessorList(this.AccessorList)
                          .WithModifiers(ChildrenProperty.Modifiers)
                          .WithAttributeLists(ChildrenProperty.Attributes)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Пример #7
0
        /// <summary>
        /// Constructs an initializer for a unique index.
        /// </summary>
        /// <param name="foreignKeyElement">The foreign index description.</param>
        /// <returns>Code to initialize a unique index.</returns>
        private static ExpressionSyntax GetForeignKeyInitializer(ForeignElement foreignKeyElement)
        {
            //        new ForeignIndex<Account,Item>("AccountSymbolKey")
            ExpressionSyntax expressionSyntax = SyntaxFactory.ObjectCreationExpression(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("ForeignIndex"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SeparatedList <TypeSyntax>(
                            new SyntaxNodeOrToken[]
            {
                SyntaxFactory.IdentifierName(foreignKeyElement.UniqueKey.Table.Name),
                SyntaxFactory.Token(SyntaxKind.CommaToken),
                SyntaxFactory.IdentifierName(foreignKeyElement.Table.Name),
            }))))
                                                .WithArgumentList(
                SyntaxFactory.ArgumentList(
                    SyntaxFactory.SeparatedList <ArgumentSyntax>(
                        new SyntaxNodeOrToken[]
            {
                SyntaxFactory.Argument(
                    SyntaxFactory.LiteralExpression(
                        SyntaxKind.StringLiteralExpression,
                        SyntaxFactory.Literal(foreignKeyElement.Name))),
                SyntaxFactory.Token(SyntaxKind.CommaToken),
                SyntaxFactory.Argument(
                    SyntaxFactory.MemberAccessExpression(
                        SyntaxKind.SimpleMemberAccessExpression,
                        SyntaxFactory.MemberAccessExpression(
                            SyntaxKind.SimpleMemberAccessExpression,
                            SyntaxFactory.MemberAccessExpression(
                                SyntaxKind.SimpleMemberAccessExpression,
                                SyntaxFactory.ThisExpression(),
                                SyntaxFactory.IdentifierName(foreignKeyElement.XmlSchemaDocument.Name)),
                            SyntaxFactory.IdentifierName(foreignKeyElement.UniqueKey.Table.Name.ToPlural())),
                        SyntaxFactory.IdentifierName(foreignKeyElement.UniqueKey.Name))),
            })));

            // .HasIndex(a => a.ItemId)
            expressionSyntax = SyntaxFactory.InvocationExpression(
                SyntaxFactory.MemberAccessExpression(
                    SyntaxKind.SimpleMemberAccessExpression,
                    expressionSyntax,
                    SyntaxFactory.IdentifierName("HasIndex")))
                               .WithArgumentList(
                SyntaxFactory.ArgumentList(
                    SyntaxFactory.SingletonSeparatedList <ArgumentSyntax>(
                        SyntaxFactory.Argument(
                            ForeignKeyExpression.GetForeignKey(foreignKeyElement)))));

            //  .HasFilter(a => a.Symbol != null)
            if (foreignKeyElement.IsNullable)
            {
                expressionSyntax = SyntaxFactory.InvocationExpression(
                    SyntaxFactory.MemberAccessExpression(
                        SyntaxKind.SimpleMemberAccessExpression,
                        expressionSyntax,
                        SyntaxFactory.IdentifierName("HasFilter")))
                                   .WithArgumentList(
                    SyntaxFactory.ArgumentList(
                        SyntaxFactory.SingletonSeparatedList <ArgumentSyntax>(
                            SyntaxFactory.Argument(NullableKeyFilterExpression.GetNullableKeyFilter(foreignKeyElement)))));
            }

            // = new UniqueIndex("SecurityFigiKey").HasIndex(s => s.Figi).HasFilter(s => s.Figi != null);
            return(expressionSyntax);
        }