internal void SetCollection(string name, IEnumerable <Instance> children)
        {
            Type dependencyType = getDependencyType(name);
            var  instance       = new EnumerableInstance(dependencyType, children);

            SetChild(name, instance);
        }
Exemple #2
0
        void IDependencyVisitor.List(ListDependency dependency)
        {
            var elements = dependency.Items.Select(instanceFor).ToArray();
            var instance = new EnumerableInstance(elements);

            Dependencies.Add(dependency.DependencyType, instance);
        }
Exemple #3
0
        protected override object build(Type pluginType, BuildSession session)
        {
            if (EnumerableInstance.IsEnumerable(pluginType))
            {
                var enumerable = new EnumerableInstance(pluginType, null);
                return(enumerable.Build(pluginType, session));
            }

            return(session.GetInstance(pluginType));
        }
        protected override object build(Type pluginType, BuildSession session)
        {
            if (EnumerableInstance.IsEnumerable(pluginType))
            {
                var enumerable = new EnumerableInstance(pluginType, null);
                return enumerable.Build(pluginType, session);
            }

            return session.CreateInstance(pluginType);
        }
        public void if_an_enumerable_type_and_there_is_no_exact_match_by_type_try_ienumerable_of_the_element_type()
        {
            var collection = new DependencyCollection();
            var instance = new EnumerableInstance(new Instance[0]);

            collection.Add(typeof (IEnumerable<IGateway>), instance);

            collection.FindByTypeOrName(typeof (IList<IGateway>), null).ShouldBeTheSameAs(instance);
            collection.FindByTypeOrName(typeof (List<IGateway>), null).ShouldBeTheSameAs(instance);
            collection.FindByTypeOrName(typeof (IGateway[]), null).ShouldBeTheSameAs(instance);
        }
        public void to_dependency_source_as_list_with_explicit_values()
        {
            var i1 = new FakeInstance();
            var i2 = new FakeInstance();
            var i3 = new FakeInstance();
            var enumerableType = typeof (List<IGateway>);
            var source = new EnumerableInstance(new Instance[] {i1, i2, i3})
                .ToDependencySource(enumerableType)
                .ShouldBeOfType<ListDependencySource>();

            source.ItemType.ShouldEqual(typeof (IGateway));
            source.Items.ShouldHaveTheSameElementsAs(i1.DependencySource, i2.DependencySource, i3.DependencySource);
        }
Exemple #7
0
        private Argument findByAll(Type argumentType, string name)
        {
            if (argumentType == null)
            {
                return(null);
            }

            var argument = _dependencies.LastOrDefault(x => x.Name == name && x.Type == argumentType);

            if (argument == null && EnumerableInstance.IsEnumerable(argumentType))
            {
                var elementType = EnumerableInstance.DetermineElementType(argumentType);
                argument = _dependencies
                           .LastOrDefault(x => x.Type == typeof(IEnumerable <>).MakeGenericType(elementType) && x.Name == name);
            }

            return(argument);
        }
        public void build_children_to_an_array()
        {
            var children = new Instance[]
            {
                new SmartInstance<ColorWidget>().WithCtorArg("color").EqualTo("red"),
                new SmartInstance<ColorWidget>().WithCtorArg("color").EqualTo("green"),
                new ObjectInstance(new AWidget())
            };

            var theInstance = new EnumerableInstance(typeof (IWidget[]), children);

            var list = theInstance.Build(typeof (IWidget[]), new StubBuildSession()).ShouldBeOfType<IWidget[]>();

            list.Length.ShouldEqual(3);

            list[0].ShouldBeOfType<ColorWidget>().Color.ShouldEqual("red");
            list[2].ShouldBeOfType<AWidget>();
        }
        public void build_children_to_a_list()
        {
            var children = new Instance[]
            {
                new SmartInstance<ColorWidget>().Ctor<string>("color").Is("red"),
                new SmartInstance<ColorWidget>().Ctor<string>("color").Is("green"),
                new ObjectInstance(new AWidget())
            };

            var theInstance = new EnumerableInstance(children);
            var list =
                theInstance.Build<IList<IWidget>>(new StubBuildSession()).As<IList<IWidget>>();

            list.Count.ShouldBe(3);

            list[0].ShouldBeOfType<ColorWidget>().Color.ShouldBe("red");
            list[2].ShouldBeOfType<AWidget>();
        }
 public override IDependencySource ToDependencySource(Type pluginType)
 {
     return(EnumerableInstance.IsEnumerable(pluginType)
         ? (IDependencySource) new AllPossibleValuesDependencySource(pluginType)
         : new DefaultDependencySource(pluginType));
 }