protected static object InvokeSourceFunction(object source, string functionName, List <ArgInfo> argsInfo, Func <MethodInfo, Type, string, bool> functionChecker)
        {
            if (argsInfo == null)
            {
                argsInfo = new List <ArgInfo>();
            }
            while (argsInfo.Count < 15)
            {
                argsInfo.Add(new ArgInfo(DependencyProperty.UnsetValue));
            }
            int        argsCount  = argsInfo.FindLastIndex(x => !x.IsUnsetValue) + 1;
            Type       targetType = (source as Type).Return(x => x.IsAbstract && x.IsSealed, () => false) ? source as Type : source.GetType();
            MethodInfo info       = GetMethodInfo(targetType, functionName, argsCount, argsInfo.Take(argsCount).Select(x => x.Type).ToArray());

            if (!functionChecker.Invoke(info, targetType, functionName))
            {
                return(DependencyProperty.UnsetValue);
            }

            ParameterInfo[] paramsInfo = info.GetParameters();
            argsCount = paramsInfo.Length;
            int count = 0;

            object[] param = argsInfo.Take(argsCount).Select(x => {
                ParameterInfo parInfo = paramsInfo[count++];
                if (x.IsUnsetValue && parInfo.IsOptional && parInfo.Attributes.HasFlag(ParameterAttributes.HasDefault))
                {
                    return(parInfo.RawDefaultValue);
                }
                else
                {
                    return(TypeCastHelper.TryCast(x.Value, parInfo.ParameterType));
                }
            }).ToArray();

            return(info.Invoke(source, param));
        }
コード例 #2
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(TypeCastHelper.TryCast(value, targetType));
 }