last ...
This commit is contained in:
@@ -39,6 +39,39 @@ namespace xCommons.Helpers
|
||||
genericMethod.Invoke(null, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoke a Generic Method of Specified Type ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="methodName"></param>
|
||||
/// <param name="runtimeTypes"></param>
|
||||
/// <param name="args"></param>
|
||||
public static void InvokeGenericMethod(
|
||||
this Type source,
|
||||
string methodName,
|
||||
Type[] runtimeTypes,
|
||||
params object[] args
|
||||
)
|
||||
{
|
||||
//
|
||||
var overLoads = source.GetGenericMethodInfo(
|
||||
methodName: methodName
|
||||
);
|
||||
if (!overLoads.HasChild())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect a Method by Generic Types ...
|
||||
// var method = overLoads.ElementAt(0);
|
||||
var method = overLoads.First(m => m.GetGenericArguments().Length == runtimeTypes.Length);
|
||||
MethodInfo genericMethod = method.MakeGenericMethod(runtimeTypes);
|
||||
|
||||
//
|
||||
genericMethod.Invoke(null, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract a Generic Method's Overloads ...
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user