Example #1
0
 private IEnumerable <object> Values(int count, Type closedType, ConstruktionPipeline pipeline)
 {
     for (var i = 0; i < count; i++)
     {
         yield return(pipeline.Construct(new ConstruktionContext(closedType)));
     }
 }
        public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline)
        {
            var closedType = context.RequestType.GetGenericArguments()[0];

            var useNull = _random.Next(1, 5);

            return(useNull == 1
                ? null
                : pipeline.Construct(new ConstruktionContext(closedType)));
        }
Example #3
0
        private HashSet <object> UniqueKeys(int count, Type key, ConstruktionPipeline pipeline, HashSet <object> items)
        {
            var newItem = pipeline.Construct(new ConstruktionContext(key));

            if (newItem != null)
            {
                items.Add(newItem);
            }

            return(items.Count == count
                ? items
                : UniqueKeys(count, key, pipeline, items));
        }
        private IList construct(Type closedType, ConstruktionPipeline pipeline)
        {
            var count = 3;
            var items = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(closedType));

            for (var i = 0; i < count; i++)
            {
                var result = pipeline.Construct(new ConstruktionContext(closedType));

                items.Add(result);
            }

            return(items);
        }
Example #5
0
        private Array construct(Type arrayType, ConstruktionPipeline pipeline)
        {
            var count = 3;

            var array = Array.CreateInstance(arrayType, count);

            for (var i = 0; i <= count - 1; i++)
            {
                var value = pipeline.Construct(new ConstruktionContext(arrayType));

                array.SetValue(value, i);
            }

            return(array);
        }
        private object construct(Func <object> ctor, ConstruktionPipeline pipeline)
        {
            var instance = ctor();

            var properties = instance.GetType()
                             .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                             .Where(x => x.CanWrite);

            foreach (var property in properties)
            {
                var result = pipeline.Construct(new ConstruktionContext(property));

                property.SetValue(instance, result);
            }

            return(instance);
        }
Example #7
0
        public object Construct(ConstruktionContext context, ConstruktionPipeline pipeline)
        {
            var instance = Activator.CreateInstance(context.RequestType);

            var properties = context.RequestType
                             .GetTypeInfo()
                             .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                             .Where(x => x.CanWrite);

            foreach (var property in properties)
            {
                var result = pipeline.Construct(new ConstruktionContext(property));

                property.SetValue(instance, result);
            }

            return(instance);
        }
        private Func <object> BuildCtor(Type type, ConstruktionPipeline pipeline)
        {
            var ctors = type.GetTypeInfo()
                        .DeclaredConstructors
                        .ToList();

            var ctor = _ctorStrategy(ctors);

            var @params = new List <ConstantExpression>();

            foreach (var parameter in ctor.GetParameters())
            {
                var ctorArg = parameter.ParameterType;

                var value = pipeline.Construct(new ConstruktionContext(ctorArg));

                @params.Add(Expression.Constant(value));
            }

            return(Expression.Lambda <Func <object> >(Expression.New(ctor, @params)).Compile());
        }