From f40f9eeac0e886879efc6fea6d2de16ea10be754 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 24 May 2026 22:48:12 +0330 Subject: [PATCH] add supports for InvokeGeneric methods to return Types supports ... --- Helpers/XGenericHelper.cs | 64 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) 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; } ///