diff --git a/Helpers/XGenericHelper.cs b/Helpers/XGenericHelper.cs index 5961031..1f7d36c 100644 --- a/Helpers/XGenericHelper.cs +++ b/Helpers/XGenericHelper.cs @@ -21,6 +21,30 @@ namespace xCommons.Helpers Type runtimeType, params object[] args ) + { + // + source.InvokeGenericMethod( + args: args, + methodName: methodName, + runtimeType: runtimeType + ); + } + + /// + /// Invoke a Generic Method of Specified Type ... + /// + /// + /// + /// + /// + /// + /// + public static TResponse InvokeGenericMethod( + this Type source, + string methodName, + Type runtimeType, + params object[] args + ) { // var overLoads = source.GetGenericMethodInfo( @@ -28,7 +52,7 @@ namespace xCommons.Helpers ); if (!overLoads.HasChild()) { - return; + return default; } // @@ -36,7 +60,11 @@ namespace xCommons.Helpers MethodInfo genericMethod = method.MakeGenericMethod(runtimeType); // - genericMethod.Invoke(null, args); + var resultObj = genericMethod.Invoke(null, args); + var result = (TResponse)resultObj; + + // + return result; } /// @@ -52,6 +80,30 @@ namespace xCommons.Helpers Type[] runtimeTypes, params object[] args ) + { + // + source.InvokeGenericMethod( + args: args, + methodName: methodName, + runtimeTypes: runtimeTypes + ); + } + + /// + /// Invoke a Generic Method of Specified Type ... + /// + /// + /// + /// + /// + /// + /// + public static TResponse InvokeGenericMethod( + this Type source, + string methodName, + Type[] runtimeTypes, + params object[] args + ) { // var overLoads = source.GetGenericMethodInfo( @@ -59,7 +111,7 @@ namespace xCommons.Helpers ); if (!overLoads.HasChild()) { - return; + return default; } // @@ -69,7 +121,11 @@ namespace xCommons.Helpers MethodInfo genericMethod = method.MakeGenericMethod(runtimeTypes); // - genericMethod.Invoke(null, args); + var resultObj = genericMethod.Invoke(null, args); + var result = resultObj.ConvertTo(); + + // + return result; } ///