This commit is contained in:
2026-05-09 22:20:59 +03:30
parent 507dd2862d
commit ffb29c6fbb
2 changed files with 52 additions and 0 deletions
+33
View File
@@ -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>
+19
View File
@@ -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);
}
}
}