当前位置: 首页>>代码示例>>C#>>正文


C# Catalog.CreateInstance方法代码示例

本文整理汇总了C#中Catalog.CreateInstance方法的典型用法代码示例。如果您正苦于以下问题:C# Catalog.CreateInstance方法的具体用法?C# Catalog.CreateInstance怎么用?C# Catalog.CreateInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Catalog的用法示例。


在下文中一共展示了Catalog.CreateInstance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Catalog_Can_Create_Object_With_Public_Readonly_Field

 public void Catalog_Can_Create_Object_With_Public_Readonly_Field()
 {
     Catalog catalog = new Catalog();
     object instance = catalog.CreateInstance<TestClass>();
     Assert.IsType<TestClass>(instance);
     TestClass cl = instance as TestClass;
     Assert.NotEqual(-1, cl.Value);
 }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:8,代码来源:ObjectTests.cs

示例2: Catalog_Can_Create_Array

        public void Catalog_Can_Create_Array()
        {
            Catalog catalog = new Catalog();
            Type array = typeof(string[]);

            object result = catalog.CreateInstance(array);

            Assert.IsType(array, result);
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:9,代码来源:CollectionTests.cs

示例3: Main

        static void Main(string[] args)
        {
            Catalog catalog = new Catalog();

            Customer customer = catalog.CreateInstance<Customer>();

            Console.WriteLine(JsonConvert.SerializeObject(customer, Formatting.Indented));

            Console.ReadKey();
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:10,代码来源:Program.cs

示例4: Catalog_Can_Create_Cyclic_Object

        public void Catalog_Can_Create_Cyclic_Object()
        {
            Catalog catalog = new Catalog();
            object instance = catalog.CreateInstance<Sample>();

            instance.Should().BeOfType<Sample>();

            Sample sample = instance as Sample;

            Veirfy(sample, 0, catalog.MaxRecursionDepth);
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:11,代码来源:CyclicObjectTests.cs

示例5: Catalog_Can_Populate_Interface

        public void Catalog_Can_Populate_Interface()
        {
            Catalog catalog = new Catalog();

            catalog.RegisterBuilder<TestInterface>()
                .WithConstructor(() => new TestClass());

            object instance = catalog.CreateInstance(typeof(TestInterface));

            instance.Should().NotBeNull();
            instance.Should().BeAssignableTo<TestInterface>();
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:12,代码来源:InterfaceTests.cs

示例6: Catalog_Can_Create_Using_Consutrctor

        public void Catalog_Can_Create_Using_Consutrctor()
        {
            Catalog catalog = new Catalog();
            object instance = catalog.CreateInstance(typeof(Sample));

            Assert.IsType(typeof(Sample), instance);
            Sample sample = instance as Sample;

            Assert.NotEqual(-1, sample.PrivateInt);
            Assert.NotNull(sample.PrivateString);
            Assert.NotNull(sample.StringProp);
            Assert.NotEqual(DateTime.MinValue, sample.DateProp);
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:13,代码来源:ObjectTests.cs

示例7: Catalog_Can_Create_Array_Of_Cyclic_Object

        public void Catalog_Can_Create_Array_Of_Cyclic_Object()
        {
            Catalog catalog = new Catalog();
            object instance = catalog.CreateInstance<Sample[]>();

            instance.Should().BeOfType<Sample[]>();
            Sample[] sample = instance as Sample[];

            foreach (Sample s in sample)
            {
                Veirfy(s, 1, catalog.MaxRecursionDepth);
            }
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:13,代码来源:CyclicObjectTests.cs

示例8: Catalog_Can_Create_Class_With_Interface_Property

        public void Catalog_Can_Create_Class_With_Interface_Property()
        {
            Catalog catalog = new Catalog();

            catalog.RegisterBuilder<TestInterface>()
                .WithConstructor(() => new TestClass());

            object instance = catalog.CreateInstance(typeof(ClassWithInterfaceProperty));
            instance.Should().BeOfType<ClassWithInterfaceProperty>();

            ClassWithInterfaceProperty sample = instance as ClassWithInterfaceProperty;
            sample.Property.Should().NotBeNull();
            sample.Property.Should().BeAssignableTo<TestInterface>();
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:14,代码来源:InterfaceTests.cs

示例9: Can_Parse_Simple_Class

        void Can_Parse_Simple_Class()
        {
            Catalog catalog = new Catalog();
            Sample instance = catalog.CreateInstance<Sample>();

            ObjectDataTree dataTree = new ObjectDataTree(instance);
            string asString = dataTree.StringValue();

            ObjectDataTree otherDataTree = new ObjectDataTree(instance);
            string otherString = otherDataTree.StringValue();

            Assert.NotEmpty(asString);
            Assert.NotEmpty(otherString);
            otherString.Should().Be(asString);
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:15,代码来源:ObjectDataTreeTests.cs

示例10: Catalog_Can_Create_Class_With_Interface_In_Constructor

        public void Catalog_Can_Create_Class_With_Interface_In_Constructor()
        {
            Catalog catalog = new Catalog();

            catalog.RegisterBuilder<TestInterface>()
                .WithConstructor(() => new TestClass());

            object instance = catalog.CreateInstance(typeof(ClassWithInterfaceInConstructor));

            instance.Should().BeOfType<ClassWithInterfaceInConstructor>();

            Assert.IsType<ClassWithInterfaceInConstructor>(instance);
            ClassWithInterfaceInConstructor sample = instance as ClassWithInterfaceInConstructor;
            var property = sample.Get();

            property.Should().NotBeNull();
            property.Should().BeAssignableTo<TestInterface>();
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:18,代码来源:InterfaceTests.cs

示例11: RunTest

        private static void RunTest(Type message)
        {
            Catalog catalog = new Catalog();
            catalog.RegisterBuilder<ObjectPropertyWithCustomValue>().WithPostConstruction(o => ((ObjectPropertyWithCustomValue)o).Value = catalog.CreateInstance<CustomObject>());
            catalog.RegisterBuilder<ArrayField>().WithConstructor(() => ArrayField.CreateInstance());

            IAssertEquality instance = (IAssertEquality)catalog.CreateInstance(message);
            Assert.IsType(message, instance);

            ObjectDataTree messageTree = new ObjectDataTree(instance);

            using (MemoryStream ms = new MemoryStream())
            {
                Serialize(new IndisposableStream(ms), instance);
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                object result = Deserialize(new IndisposableStream(ms), message);

                ObjectDataTree resultTree = new ObjectDataTree(result);

                resultTree.StringValue().Should().Be(messageTree.StringValue());

                instance.AssertEquality(result);
            }
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:25,代码来源:CatalogWithSamplesObjectsTests.cs

示例12: Catalog_Can_Create_List

 public void Catalog_Can_Create_List()
 {
     Catalog catalog = new Catalog();
     object result = catalog.CreateInstance(typeof(List<string>));
     Assert.IsType<List<string>>(result);
 }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:6,代码来源:CollectionTests.cs

示例13: Catalog_Can_Create_Object_With_Composed_Collection

        public void Catalog_Can_Create_Object_With_Composed_Collection()
        {
            Catalog catalog = new Catalog();
            object result = catalog.CreateInstance(typeof(TestClass));

            result.Should().BeOfType<TestClass>();

            TestClass instance = result as TestClass;
            instance.Value.Should().NotBeNull();
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:10,代码来源:CollectionTests.cs

示例14: Catalog_Can_Create_Non_Empty_List

        public void Catalog_Can_Create_Non_Empty_List()
        {
            Catalog catalog = new Catalog();

            List<List<string>> resultedLists = new List<List<string>>();
            for (int i = 0; i < 100; i++) // 100 times since rnd might generate an empty list
            {
                object result = catalog.CreateInstance(typeof(List<string>));
                Assert.IsType<List<string>>(result);
                resultedLists.Add(result as List<string>);
            }
            Assert.True(resultedLists.Any(l => l.Any()));
        }
开发者ID:etishor,项目名称:TestDataGenerator,代码行数:13,代码来源:CollectionTests.cs


注:本文中的Catalog.CreateInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。