【发布时间】:2020-01-08 12:58:58
【问题描述】:
我目前正在向现有 API 添加新功能。假设我有一个带有泛型类型参数的PerformTediousOperation 方法:
void PerformTediousOperation<T>()
这个方法在Operator 类中,可以这样调用:
operatorInstance.PerformTediousOperation<T>()
每当用户使用Operable 属性标记类型时,我想创建一个新的Operator 实例并调用此方法。
目前,这是我卡住的地方:
MethodReference performTediousOperationMethodReference =
new MethodReference(
name: "PerformTediousOperation",
returnType: moduleDefinition.TypeSystem.Void,
declaringType: operatorTypeReference)
{
HasThis = true
};
发出的 IL 代码(在 C# 中)只是 PerformTediousOperation();。
我该如何解决这个问题,以便发出的代码改为PerformTediousOperation<T>(),而T 将在运行时确定?
如果需要更多信息,请告诉我。
【问题讨论】:
-
@canton7 谢谢,我知道该怎么做了。
标签: c# cil mono.cecil