Ejemplo n.º 1
0
        private static Class DeclareClass()
        {
            var da       = new DynamicAssembly();
            var bindings = new PropertyBinding[]
            {
                new PropertyBinding {
                    EntityProperty = "Id", DtoProperty = "Id", Mode = BindingMode.TwoWay, IsPrimaryKey = true, PrimaryKeyOrder = 1
                },
                new PropertyBinding {
                    EntityProperty = "Name", DtoProperty = "Name", Mode = BindingMode.TwoWay, IsPrimaryKey = true, PrimaryKeyOrder = 0
                },
                new PropertyBinding {
                    EntityProperty = "DtoToEntity", DtoProperty = "DtoToEntity", Mode = BindingMode.OneWayToEntity
                },
                new PropertyBinding {
                    EntityProperty = "EntityToDto", DtoProperty = "EntityToDto", Mode = BindingMode.OneWayToDto
                },
                new PropertyBinding {
                    EntityProperty = "X", DtoProperty = "Fields.X", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Sample.Id", DtoProperty = "Sample.R.Id", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Sample.X", DtoProperty = "Fields.Y", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Sample.Description", DtoProperty = "Sample.Description", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Alternation", DtoProperty = "Alternation", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Alternation.PublishedDate", DtoProperty = "PublishedDate", Mode = BindingMode.OneWayToDto
                },
                new PropertyBinding {
                    EntityProperty = "Array", DtoProperty = "Array", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "List", DtoProperty = "List", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Middle.Nested", DtoProperty = "Middle.Nested", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Middle.Nested.Array", DtoProperty = "Middle2.Array", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Middle.Nested.List", DtoProperty = "Middle3.List", Mode = BindingMode.TwoWay
                },
            };

            var nestedBindings = new PropertyBinding[]
            {
                new PropertyBinding {
                    EntityProperty = "Id", DtoProperty = "Id", Mode = BindingMode.TwoWay, IsPrimaryKey = true, PrimaryKeyOrder = 1
                },
                new PropertyBinding {
                    EntityProperty = "Name", DtoProperty = "Name", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "X", DtoProperty = "Fields.X", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Sample.Id", DtoProperty = "Sample.R.Id", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Sample.X", DtoProperty = "Fields.Y", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Sample.Description", DtoProperty = "Sample.Description", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Alternation", DtoProperty = "Alternation", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Alternation.PublishedDate", DtoProperty = "PublishedDate", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Array", DtoProperty = "Array", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "List", DtoProperty = "List", Mode = BindingMode.TwoWay
                },
            };

            var bindings2 = new PropertyBinding[]
            {
                new PropertyBinding {
                    EntityProperty = "Content", DtoProperty = "Content", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Id", DtoProperty = "Id", Mode = BindingMode.TwoWay, IsPrimaryKey = true, PrimaryKeyOrder = 1
                },
            };

            var bindings3 = new PropertyBinding[]
            {
                new PropertyBinding {
                    EntityProperty = "Token", DtoProperty = "Token", Mode = BindingMode.TwoWay
                },
                new PropertyBinding {
                    EntityProperty = "Des", DtoProperty = "Des", Mode = BindingMode.TwoWay, IsPrimaryKey = true, PrimaryKeyOrder = 1
                },
            };
            var cls1   = da.DeclareClass("Test", typeof(Source), bindings);
            var cls1_1 = da.DeclareClass("NestedSource", typeof(NestedSource), nestedBindings);
            var cls2   = da.DeclareClass("Test2", typeof(Source2), bindings2);
            var cls3   = da.DeclareClass("Test3", typeof(Element), bindings3);

            da.Build();

            var type1 = cls1.GetBuiltType();

            return(cls1);
        }