//////////////////////////////////////// public static DynamicCallResult CallMethod(this Object Obj, String MethodName, IList <Object> Parameters) { MethodInfo methodInfo = MyReflectionHelper.GetMethod( Obj, MethodName, Parameters == null ? 0 : Parameters.Count); if (methodInfo != null) { IList <ParameterInfo> parametersInfo = methodInfo.GetParameters(); List <Object> finalParameters = new List <Object>(); Int32 index = -1; foreach (ParameterInfo parameterInfo in parametersInfo) { index++; Object val = MyTypeHelper.ConvertTo( Parameters[index], parameterInfo.ParameterType); finalParameters.Add(val); } return(new DynamicCallResult() { Value = Obj is Type? methodInfo.Invoke(null, finalParameters.ToArray()) : methodInfo.Invoke(Obj, finalParameters.ToArray()) }); } return(null); }
////////////////////////////////////////////////// public Object GetValueOrMethod(Object Item, String PropertyName, Int32 ParametersCount, out Boolean FoundValue) { FoundValue = false; var getter = GetGetter(Item, PropertyName); if (getter != null) { FoundValue = true; try { return(getter(Item)); } catch { return(MyReflectionHelper.GetValue( Item, PropertyName)); } } else { var method = MyReflectionHelper.GetMethod(Item, PropertyName, ParametersCount); if (method != null) { FoundValue = true; } return(method); } return(null); }