當前位置: 首頁>>代碼示例>>C#>>正文


C# Factory.Create方法代碼示例

本文整理匯總了C#中System.Factory.Create方法的典型用法代碼示例。如果您正苦於以下問題:C# Factory.Create方法的具體用法?C# Factory.Create怎麽用?C# Factory.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Factory的用法示例。


在下文中一共展示了Factory.Create方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: FirstTest

        public void FirstTest()
        {
            var carFactory = new Factory<Car>();
            var planeFactory = new Factory<Plane>();
            IProduct<Car> carProduct = carFactory.Create<Toyota>();
            IProduct<Plane> planeProduct = planeFactory.Create<Boeing>();
            carProduct.Operate();
            planeProduct.Operate();

            carProduct = carFactory.Create<Engine<Car>>();
            carProduct.Operate();
        }
開發者ID:TomPallister,項目名稱:PoC,代碼行數:12,代碼來源:Tests.cs

示例2: CreateNew_ShouldInvokePassedCallbackWithNewEntity

        public void CreateNew_ShouldInvokePassedCallbackWithNewEntity()
        {
            var factory = new Factory();
            var entity = factory.Create<TestEntity>(e => e.Name = "Explicit Value");

            Assert.Equal("Explicit Value", entity.Name);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:7,代碼來源:FactoryTests.cs

示例3: CreateNew_ShouldCreateInstanceOfTypeParameter

        public void CreateNew_ShouldCreateInstanceOfTypeParameter()
        {
            var factory = new Factory();
            var entity = factory.Create<SimpleTestEntity>();

            Assert.NotNull(entity);
            Assert.IsAssignableFrom<SimpleTestEntity>(entity);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:8,代碼來源:FactoryTests.cs

示例4: CreateNew_ShouldPopulatePrimatives_WhenNotUsingFactoryFunction

        public void CreateNew_ShouldPopulatePrimatives_WhenNotUsingFactoryFunction()
        {
            var factory = new Factory();
            factory.ValueObjects.RegisterFactoryFunction(() => "Expected");

            var entity = factory.Create<TestEntity>();

            Assert.Equal("Expected", entity.Name);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:9,代碼來源:FactoryTests.cs

示例5: CreateNew_ShouldPassItselfToRegisteredFactoryMethod_WhenFactoryMethodWantsIt

        public void CreateNew_ShouldPassItselfToRegisteredFactoryMethod_WhenFactoryMethodWantsIt()
        {
            Factory actual = null;
            var factory = new Factory();
            factory.Entities.RegisterFactoryFunction<TestEntity>((f) => { actual = f; return new TestEntity(); });

            factory.Create<TestEntity>();
            Assert.Same(factory, actual);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:9,代碼來源:FactoryTests.cs

示例6: CreateNew_ShouldInvokePassedCallbackWithNewEntity_WhenEntityIsCreatedWithRegisteredFunction

        public void CreateNew_ShouldInvokePassedCallbackWithNewEntity_WhenEntityIsCreatedWithRegisteredFunction()
        {
            var factory = new Factory();
            factory.Entities.RegisterFactoryFunction(() => new TestEntity { Name = "Initial" });

            var entity = factory.Create<TestEntity>(e => e.Name = "Explicit Value");

            Assert.Equal("Explicit Value", entity.Name);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:9,代碼來源:FactoryTests.cs

示例7: Main

        static void Main(string[] args)
        {
            var factory = new Factory("MyApp", new MyLogger());

            // Register the type.
            factory.Type("MyType", typeof(MyType));

            // Create an instance and pass in constructor arguments.
            var myFactoryCreatedObject = factory.Create<MyType>("MyType", "Hello", "Computer");

            Console.WriteLine(myFactoryCreatedObject.Message);
        }
開發者ID:Real-Serious-Games,項目名稱:Factory,代碼行數:12,代碼來源:Program.cs

示例8: FactoryTests_PropertySetting_WhenCreatedWithDefaultCtor

 public FactoryTests_PropertySetting_WhenCreatedWithDefaultCtor()
 {
     factory = new Factory();
     entity = factory.Create<SimpleTestEntity>();
 }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:5,代碼來源:FactoryTests_PropertySetting_WhenCreatedWithDefaultCtor.cs

示例9: CreateNew_ShouldThrowMissingMethodException_WhenTypeHasNoDefaultCtorAndNoCustomCreateMethod

        public void CreateNew_ShouldThrowMissingMethodException_WhenTypeHasNoDefaultCtorAndNoCustomCreateMethod()
        {
            var factory = new Factory();

            var exception = Assert.Throws<MissingMethodException>(
                            () => factory.Create<SimpleTestEntityNoDefaultCtor>());

            var expectedMessage = string.Format(
                "Unable to create instance of {0} because the requested type does not define a parameterless constructor and no custom factory method was registered.",
                typeof(SimpleTestEntityNoDefaultCtor).FullName);

            Assert.Equal(expectedMessage, exception.Message);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:13,代碼來源:FactoryTests.cs

示例10: CreateNew_ShouldStillUseRegisteredFactoryFunction_WhenTypeDoesNotHaveADefaultCtor

        public void CreateNew_ShouldStillUseRegisteredFactoryFunction_WhenTypeDoesNotHaveADefaultCtor()
        {
            var factory = new Factory();
            factory.Entities.RegisterFactoryFunction(() => new SimpleTestEntityNoDefaultCtor("a"));

            var entity = factory.Create<SimpleTestEntityNoDefaultCtor>();
            Assert.NotNull(entity);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:8,代碼來源:FactoryTests.cs

示例11: CreateNew_ShouldUseRegisteredFactoryFunction

        public void CreateNew_ShouldUseRegisteredFactoryFunction()
        {
            var expectedEntity = new SimpleTestEntity();
            var factory = new Factory();
            factory.Entities.RegisterFactoryFunction(() => expectedEntity);

            var entity = factory.Create<SimpleTestEntity>();

            Assert.Same(expectedEntity, entity);
        }
開發者ID:davidwalker,項目名稱:GuineaPig,代碼行數:10,代碼來源:FactoryTests.cs


注:本文中的System.Factory.Create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。