當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。