Exemplo n.º 1
0
 public ComposeParameterStrategy(CanConvertTypePredicate predicate, ConvertTypeMethod converter)
 {
   Predicate = predicate;
   Converter = converter;
 }
Exemplo n.º 2
0
    protected static object[] ComposeParameters(object[] arguments, ParameterInfo[] parameters, CanConvertTypePredicate predicate, ConvertTypeMethod converter)
    {
      if (arguments.Length != parameters.Length) return null;

      var result = new object[arguments.Length];

      for (int i = 0; i < parameters.Length; i++)
      {
        var parameterType = parameters[i].ParameterType;
        var argument = arguments[i];

        //NOTE: ref, out
        //out and ref parameters handling
        ScopeValueReference vr = null;
        if (parameters[i].ParameterType.IsByRef)
        {
          vr = (ScopeValueReference)argument;
          argument = vr.Value;
        }

        if (predicate(argument, parameterType))
        {
          var converted = converter(argument, parameterType);
          if (converted == NoResult) return null;

          //NOTE: ref, out
          if (vr == null)
            result[i] = converted;
          else
          {
            vr.ConvertedValue = converted;
            result[i] = vr;
          }

        }
        else
        {
          return null;
        }

      }

      return result;
    }
 public ComposeParameterStrategy(CanConvertTypePredicate predicate, ConvertTypeMethod converter)
 {
     Predicate = predicate;
     Converter = converter;
 }
        protected static object[] ComposeParameters(object[] arguments, ParameterInfo[] parameters, CanConvertTypePredicate predicate, ConvertTypeMethod converter)
        {
            if (arguments.Length != parameters.Length)
            {
                return(null);
            }

            object[] result = new object[arguments.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                Type   parameterType = parameters[i].ParameterType;
                object argument      = arguments[i];

                if (predicate(argument, parameterType))
                {
                    object converted = converter(argument, parameterType);
                    if (converted == ObjectBinder.NoResult)
                    {
                        return(null);
                    }

                    result[i] = converted;
                }
                else
                {
                    return(null);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        protected static object[] ComposeParameters(object[] arguments, ParameterInfo[] parameters, CanConvertTypePredicate predicate, ConvertTypeMethod converter)
        {
            if (arguments.Length != parameters.Length) return null;

              object[] result = new object[arguments.Length];

              for (int i = 0; i < parameters.Length; i++)
              {
            Type parameterType = parameters[i].ParameterType;
            object argument = arguments[i];

            if (predicate(argument, parameterType))
            {
              object converted = converter(argument, parameterType);
              if (converted == ObjectBinder.NoResult) return null;

              result[i] = converted;
            }
            else
            {
              return null;
            }
              }

              return result;
        }
Exemplo n.º 6
0
        protected static object[] ComposeParameters(object[] arguments, ParameterInfo[] parameters, CanConvertTypePredicate predicate, ConvertTypeMethod converter)
        {
            if (arguments.Length != parameters.Length)
            {
                return(null);
            }

            var result = new object[arguments.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                var parameterType = parameters[i].ParameterType;
                var argument      = arguments[i];

                //NOTE: ref, out
                //out and ref parameters handling
                ScopeValueReference vr = null;
                if (parameters[i].ParameterType.IsByRef)
                {
                    vr       = (ScopeValueReference)argument;
                    argument = vr.Value;
                }

                if (predicate(argument, parameterType))
                {
                    var converted = converter(argument, parameterType);
                    if (converted == NoResult)
                    {
                        return(null);
                    }

                    //NOTE: ref, out
                    if (vr == null)
                    {
                        result[i] = converted;
                    }
                    else
                    {
                        vr.ConvertedValue = converted;
                        result[i]         = vr;
                    }
                }
                else
                {
                    return(null);
                }
            }

            return(result);
        }