当前位置: 首页>>代码示例>>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;未经允许,请勿转载。