コード例 #1
0
        public Expression ToExpression(ParameterExpression session, ParameterExpression context)
        {
            var getData = Expression.Call(context, ContextMethod.MakeGenericMethod(_elementType));

            if (_enumerationType.IsArray || _enumerationType.GetGenericTypeDefinition() == typeof(IList <>))
            {
                return(Expression.Call(null, ToArrayMethod.MakeGenericMethod(_elementType), getData));
            }

            if (_enumerationType.GetGenericTypeDefinition() != typeof(List <>))
            {
                return(getData);
            }

            return(ListDependencySource.ToExpression(_elementType, getData));
        }
コード例 #2
0
        public void can_build_with_list_dependency()
        {
            var gateway1 = new StubbedGateway();
            var gateway2 = new StubbedGateway();
            var gateway3 = new StubbedGateway();

            var build = new ConcreteBuild<GatewayListUser>();
            var array = new ListDependencySource(typeof (IGateway),
                Constant.For(gateway1),
                Constant.For(gateway2),
                Constant.For(gateway3));

            build.ConstructorArgs(array);

            var arrayUser = build.Build<GatewayListUser>(new FakeBuildSession());

            arrayUser.Gateways.ShouldHaveTheSameElementsAs(gateway1, gateway2, gateway3);
        }