last ...
This commit is contained in:
@@ -39,6 +39,39 @@ namespace xCommons.Helpers
|
|||||||
genericMethod.Invoke(null, args);
|
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>
|
/// <summary>
|
||||||
/// Extract a Generic Method's Overloads ...
|
/// Extract a Generic Method's Overloads ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace xCommons.Models
|
||||||
|
{
|
||||||
|
public class XServiceDescriptor
|
||||||
|
{
|
||||||
|
public Type Service { get; set; }
|
||||||
|
public Type Implementation { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class XServiceDescriptor<TService, TImplmentation> : XServiceDescriptor
|
||||||
|
{
|
||||||
|
public XServiceDescriptor() : base()
|
||||||
|
{
|
||||||
|
Service = typeof(TService);
|
||||||
|
Implementation = typeof(TImplmentation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user