【发布时间】:2021-09-01 04:25:34
【问题描述】:
我想在我的课堂上添加一个Action<,> 归档,使用Mono.cecill 创建。
但我无法理解不确定性的类型。
我如何创建它?
我是这样写的,但是错了:
var tmpFieldDefinition = (FieldDefinition) methodAttributes.Body.Instructions[2].Operand;
TypeReference tmpAction = module.ImportReference(typeof(Action<,>));
var gp = new GenericParameter(tmpFieldDefinition.FieldType);
tmpAction.GenericParameters[0] = gp;
tmpAction.GenericParameters[1] = gp;
CreateAngValueChangeEventField(typeDefinition, $"{name}ValueChange", tmpAction);
我的期望是:
public Action<string, string> OnDataModeTestStr2ValueChange;
但是生成的:
public Action<,> OnDataModeTestStr2ValueChange;
问候。
【问题讨论】:
-
什么是“错”?
-
所以我期望的是:public Action
OnDataModeTestStr2ValueChange;但是生成的:public Action OnDataModeTestStr2ValueChange; -
我不知道 mono.cecil 也不知道这里做了什么,但是:
typeof(Action<string, string>)? -
是的,但是字符串是不确定的类型,可以是任何类型,比如int,long……类型是form tmpFieldDefinition,我不确定。
标签: c# delegates action cil mono.cecil