Пример #1
0
        private void ProcessConstructor(ConstructorResult constructor)
        {
            ParameterInfo[] parms = constructor.constructor.GetParameters();

            for (int i = 0; i < constructor.types.Length; i++)
            {
                ParameterInfo parameter   = parms[i];
                Expression    value       = _expression.ConstructorArguments[i];
                Type          definedType = null;
                if (_definedParameters.Length > i)
                {
                    definedType = _definedParameters[i];
                }

                Type inferredType = null;
                if (value is ValueExpression)
                {
                    inferredType = GetValueType(parameter, (ValueExpression)value);
                }
                else if (value is ArrayExpression)
                {
                    if (_context.GetTypeHandler(parameter.ParameterType).IsCollection())
                    {
                        inferredType = parameter.ParameterType;
                    }
                }
                constructor.types[i] = GetBestMatch(parameter.ParameterType, definedType, inferredType);
            }
        }
Пример #2
0
        private void ComputeScore(ConstructorResult constructor)
        {
            ParameterInfo[] parms = constructor.constructor.GetParameters();
            // should have already been checked, but just double-check
            Debug.Assert(parms.Length == _expression.ConstructorArguments.Count, "Constructors with different argument counts should have been removed already");

            int score = 0;

            // check to make sure each arg type is compatible, if its set
            for (int i = 0; i < parms.Length; i++)
            {
                Type exprType = null;
                if (constructor.types[i] != null)
                {
                    exprType = constructor.types[i];
                }

                //+2 for each exact match
                if (exprType != null && parms[i].ParameterType == exprType)
                {
                    score += 2;
                }
                //+1 for each compatible match
                else if (exprType != null && parms[i].ParameterType.IsAssignableFrom(exprType))
                {
                    score += 1;
                }
                // make sure incompatible types are weeded out
                else if (exprType != null && !IsTypeCompatible(parms[i].ParameterType, exprType))
                {
                    score -= parms.Length * 5;
                }
            }
            constructor.score = score;
        }
Пример #3
0
 public async Task <ActionResult <ConstructorResult> > Put(int id, [FromBody] ConstructorResult value)
 {
     return(await this.baseController.Put(id, value));
 }
Пример #4
0
 public async Task <ActionResult <ConstructorResult> > Post([FromBody] ConstructorResult value)
 {
     return(await this.baseController.Post(value));
 }