コード例 #1
0
        public void TryGetBuilder2()
        {
            var provider   = new FactoryProvider();
            var collection = new FactoryCollection <Type>();
            var factory    = new Factory <string>();

            factory.Add("empty", new GameObjectBuilderEmpty());
            factory.Add("prefab", new GameObjectBuilder(new GameObject("prefab")));
            collection.Add(typeof(IGameObjectBuilder), factory);
            provider.Add(collection);

            bool result1 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "empty", out IGameObjectBuilder builder1);
            bool result2 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "prefab", out IGameObjectBuilder builder2);
            bool result3 = provider.TryGetBuilder(typeof(int), "empty", out IBuilder builder3);
            bool result4 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "prefab2", out IGameObjectBuilder builder4);

            Assert.True(result1);
            Assert.True(result2);
            Assert.False(result3);
            Assert.False(result4);
            Assert.NotNull(builder1);
            Assert.NotNull(builder2);
            Assert.Null(builder3);
            Assert.Null(builder4);
        }