초기커밋
This commit is contained in:
41
ServerBase/Meta/MetaValidation/MethodInfoExtentions.cs
Normal file
41
ServerBase/Meta/MetaValidation/MethodInfoExtentions.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace ServerBase;
|
||||
|
||||
public static class MethodInfoExtentions
|
||||
{
|
||||
public static TDelegate compile<TDelegate>(MethodInfo mi)
|
||||
{
|
||||
ParameterExpression? @this = null;
|
||||
if (!mi.IsStatic)
|
||||
{
|
||||
@this = Expression.Parameter(mi.DeclaringType!, "this");
|
||||
}
|
||||
|
||||
var parameters = new List<ParameterExpression>();
|
||||
if (@this != null)
|
||||
{
|
||||
parameters.Add(@this);
|
||||
}
|
||||
|
||||
foreach (var parameter in mi.GetParameters())
|
||||
{
|
||||
parameters.Add(Expression.Parameter(parameter.ParameterType, parameter.Name));
|
||||
}
|
||||
|
||||
Expression? call = null;
|
||||
if (@this != null)
|
||||
{
|
||||
call = Expression.Call(@this, mi, parameters.Skip(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(mi, parameters);
|
||||
}
|
||||
|
||||
return Expression.Lambda<TDelegate>(call, parameters).Compile();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user