示例#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));
        }
示例#2
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);
        }
示例#3
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);
        }