Exemplo n.º 1
0
        //readonly Type[] _targetGenericArgBindings;

        public static DuckMethodBindingOption TryBind(MethodInfo adaptee, MethodInfo candidate)
        {
            var adapteeParams   = adaptee.GetParameters();
            var candidateParams = candidate.GetParameters();

            if (adapteeParams.Length != candidateParams.Length)
            {
                return(null);
            }

            var retValBinding = DuckValueBindingOption.Get(candidate.ReturnType, adaptee.ReturnType);

            if (!retValBinding.Bindable)
            {
                return(null);
            }

            var paramBindings = new List <DuckParamBindingOption>(adapteeParams.Length);

            for (int i = 0; i < adapteeParams.Length; ++i)
            {
                var paramBinding = DuckParamBindingOption.Get(adapteeParams[i], candidateParams[i]);
                if (!paramBinding.Bindable)
                {
                    return(null);
                }
                paramBindings.Add(paramBinding);
            }

            return(new StandardMethodBinding(adaptee, candidate, retValBinding, paramBindings));
        }
 internal ImplicitNullableValueBinding(bool fromTypeNullable, Type fromType, Type toType, Type coreToType, DuckValueBindingOption coreBinding)
 {
     _fromTypeNullable = fromTypeNullable;
     _fromType         = fromType;
     _toType           = toType;
     _coreToType       = coreToType;
     _coreBinding      = coreBinding;
 }
 internal ImplicitNullableValueBinding(bool fromTypeNullable, Type fromType, Type toType, Type coreToType, DuckValueBindingOption coreBinding)
 {
     _fromTypeNullable = fromTypeNullable;
     _fromType = fromType;
     _toType = toType;
     _coreToType = coreToType;
     _coreBinding = coreBinding;
 }
Exemplo n.º 4
0
 StandardMethodBinding(MethodInfo adaptee, MethodInfo target, DuckValueBindingOption retValBinding, List<DuckParamBindingOption> paramBindings)
 {
     _adaptee = adaptee;
     _target = target;
     _retValBinding = retValBinding;
     _paramBindings = paramBindings;
     _score = _retValBinding.Score + _paramBindings.Sum(a => a.Score);
     //_targetGenericArgBindings = new Type[target.GetGenericArguments().Length];
 }
Exemplo n.º 5
0
 StandardMethodBinding(MethodInfo adaptee, MethodInfo target, DuckValueBindingOption retValBinding, List <DuckParamBindingOption> paramBindings)
 {
     _adaptee       = adaptee;
     _target        = target;
     _retValBinding = retValBinding;
     _paramBindings = paramBindings;
     _score         = _retValBinding.Score + _paramBindings.Sum(a => a.Score);
     //_targetGenericArgBindings = new Type[target.GetGenericArguments().Length];
 }
Exemplo n.º 6
0
        public static DuckParamBindingOption TryBind(ParameterInfo fromParam, ParameterInfo toParam)
        {
            if (fromParam.IsOut != toParam.IsOut || fromParam.IsRetval != toParam.IsRetval)
            {
                return(null);
            }

            var valueBinding = DuckValueBindingOption.Get(fromParam.ParameterType, toParam.ParameterType);

            return(valueBinding.Bindable ? new InParamBinding(valueBinding) : null);
        }
Exemplo n.º 7
0
        public static DuckParamBindingOption TryBind(ParameterInfo fromParam, ParameterInfo toParam)
        {
            if (!fromParam.IsOut || !toParam.IsOut)
            {
                return(null);
            }

            var toType       = toParam.ParameterType.GetElementType();
            var fromType     = fromParam.ParameterType.GetElementType();
            var valueBinding = DuckValueBindingOption.Get(toType, fromType);

            return(valueBinding.Bindable ? new OutParamBinding(valueBinding, fromType, toType) : null);
        }
Exemplo n.º 8
0
 public InParamBinding(DuckValueBindingOption valueBinding)
 {
     _valueBinding = valueBinding;
 }
Exemplo n.º 9
0
 public OutParamBinding(DuckValueBindingOption valueBinding, Type fromType, Type toType)
 {
     _valueBinding = valueBinding;
     _fromType = fromType;
     _toType = toType;
 }
Exemplo n.º 10
0
 public InParamBinding(DuckValueBindingOption valueBinding)
 {
     _valueBinding = valueBinding;
 }
Exemplo n.º 11
0
 public OutParamBinding(DuckValueBindingOption valueBinding, Type fromType, Type toType)
 {
     _valueBinding = valueBinding;
     _fromType     = fromType;
     _toType       = toType;
 }