我正在将开源库从常规 .NET 4 Client Profile 移植到 DNX Core 5.0。有相当多的库更改,属性或方法被移动或完全删除。我看过这个答案但它在我的情况下不起作用,因为该方法已被删除。
问题之一我有一段代码MethodBase.GetCurrentMethod()
叫做。 API 中不再存在此方法。剩下的唯一类似的方法是:
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle);
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType);
但我不确定“句柄”是什么。我需要获取 MethodBase 才能访问其参数,然后处理它们以进行 REST API 查询。这是在 .NET 4 中构建对象的代码:
public static Annotation Annotation(string query = null, string text = null, string type = null, string name = null, string entity = null, int limit = 25, int offset = 0)
{
var search = Help.SearchToString(MethodBase.GetCurrentMethod(), query, text, type, name, entity);
return Help.Find<Annotation>(search, limit, offset, "annotation");
}
然后在这里使用它:
public static string SearchToString(MethodBase m, params object[] search)
{
var paras = m.GetParameters();
var result = string.Empty;
for (var i = 0; i < search.Length; i++)
{
if (search[i] != null)
{
if (i == 0)
{
result += search[i] + "%20AND%20";
}
else
{
result += paras[i].Name.ToLower() + ":" + search[i] + "%20AND%20";
}
}
}
return result.LastIndexOf("%20AND%20", StringComparison.Ordinal) > 0
? result.Substring(0, result.LastIndexOf("%20AND%20", StringComparison.Ordinal))
: result;
}
我还可以通过什么其他方式访问MethodBase
对象参数在SearchToString()
如果我不能轻易通过上述方法MethodBase
作为参数?