add supports for InvokeGeneric methods to return Types supports ...
This commit is contained in:
@@ -21,6 +21,30 @@ namespace xCommons.Helpers
|
||||
Type runtimeType,
|
||||
params object[] args
|
||||
)
|
||||
{
|
||||
//
|
||||
source.InvokeGenericMethod<object>(
|
||||
args: args,
|
||||
methodName: methodName,
|
||||
runtimeType: runtimeType
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoke a Generic Method of Specified Type ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="methodName"></param>
|
||||
/// <param name="runtimeType"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static TResponse InvokeGenericMethod<TResponse>(
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,6 +80,30 @@ namespace xCommons.Helpers
|
||||
Type[] runtimeTypes,
|
||||
params object[] args
|
||||
)
|
||||
{
|
||||
//
|
||||
source.InvokeGenericMethod<object>(
|
||||
args: args,
|
||||
methodName: methodName,
|
||||
runtimeTypes: runtimeTypes
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoke a Generic Method of Specified Type ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="methodName"></param>
|
||||
/// <param name="runtimeTypes"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static TResponse InvokeGenericMethod<TResponse>(
|
||||
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<TResponse>();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user