Exemplo n.º 1
0
        public Expression BuildExpression(TypeMapPlanBuilder builder)
        {
            if (!CanResolve)
            {
                return(null);
            }

            var ctorArgs = CtorParams.Select(p => p.CreateExpression(builder));

            ctorArgs =
                ctorArgs.Zip(Ctor.GetParameters(),
                             (exp, pi) => exp.Type == pi.ParameterType ? exp : Convert(exp, pi.ParameterType))
                .ToArray();
            var newExpr = New(Ctor, ctorArgs);

            return(newExpr);
        }
Exemplo n.º 2
0
        public override IEnumerable <Variable> FindVariables(IMethodVariables chain)
        {
            var parameters = Ctor.GetParameters();

            for (var i = 0; i < parameters.Length; i++)
            {
                if (Parameters[i] == null)
                {
                    var parameter = parameters[i];
                    Parameters[i] = chain.FindVariable(parameter.ParameterType);
                }
            }

            foreach (var parameter in Parameters)
            {
                yield return(parameter);
            }

            foreach (var setter in Setters)
            {
                setter.FindVariable(chain);
            }

            foreach (var setter in Setters)
            {
                yield return(setter.Variable);
            }


            if (ActivatorFrames.Any())
            {
                var standin = new StandinMethodVariables(Variable, chain);

                foreach (var frame in ActivatorFrames)
                {
                    foreach (var variable in frame.FindVariables(standin))
                    {
                        yield return(variable);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public Expression BuildExpression(
            TypeMapRegistry typeMapRegistry,
            ParameterExpression srcParam,
            ParameterExpression ctxtParam)
        {
            if (!CanResolve)
            {
                return(null);
            }

            var ctorArgs = CtorParams.Select(p => p.CreateExpression(typeMapRegistry, srcParam, ctxtParam));

            ctorArgs =
                ctorArgs.Zip(Ctor.GetParameters(),
                             (exp, pi) => exp.Type == pi.ParameterType ? exp : Convert(exp, pi.ParameterType))
                .ToArray();
            var newExpr = New(Ctor, ctorArgs);

            return(newExpr);
        }
Exemplo n.º 4
0
        public IOption <object> Create(IMap <string, object> values)
        {
            var parameters = Ctor.GetParameters().Select(p => values[p.Name]).ToArray();

            if (!parameters.IsSome)
            {
                return(Option <object> .None());
            }

            var instance = Ctor.Invoke(parameters.Value);

            foreach (var p in Dependencies.OfType <PropertyDependency>())
            {
                var propOption = values[p.Name];
                if (propOption.IsSome)
                {
                    p.SetValue(instance, propOption.Value);
                }
            }

            return(instance.Some());
        }