Esempio n. 1
0
        public Expression Resolve(Expression input, Expression output, string prefix)
        {
            if (!_constructorChecked && _config != null && _config.Resolve(".ctor", input, out Expression ctor))
            {
                return(ctor);
            }

            _constructorChecked = true;

            var constructor = output.Type.GetConstructor(); // default constructor

            if (constructor != null && output.Type.IsClass())
            {
                return(Expression.New(constructor));
            }

            var inputProperties = input.Type.GetRuntimeProperties()
                                  .Where(p => p.GetMethod.IsPublic && !p.GetMethod.IsStatic && p.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
                                  .ToList();

            var outputConstructors = output.Type.GetConstructors()
                                     .OrderByDescending(p => p.GetParameters().Length)
                                     .ToArray();

            if (outputConstructors.Length == 0)
            {
                return(null);
            }

            _input  = input;
            _output = output;

            return(FindConstructor(outputConstructors, inputProperties, prefix));
        }