Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将泛型对象作为参数加载的操作码_C#_Reflection_Typebuilder - Fatal编程技术网

C# 将泛型对象作为参数加载的操作码

C# 将泛型对象作为参数加载的操作码,c#,reflection,typebuilder,C#,Reflection,Typebuilder,我正在调用一个方法,其中一个参数的类型为object。如何将其加载到堆栈上?我知道枚举有整数等价物,但我也希望使用它将使用Type.CreateInstance创建的实际对象作为参数放入方法addoutput //method addoutput of type overriden by the typebuilder is of form addoutput(object o) //enumType is a Type that is an enumeration TypeBuilder

我正在调用一个方法,其中一个参数的类型为object。如何将其加载到堆栈上?我知道枚举有整数等价物,但我也希望使用它将使用Type.CreateInstance创建的实际对象作为参数放入方法addoutput

//method addoutput of type overriden by the typebuilder is of form    addoutput(object o)
//enumType is a Type that is an enumeration
TypeBuilder tb;
//tb is initialized here
//override constructor
ConstructorBuilder ctor1 = tb.DefineConstructor(MethodAttributes.Public,    CallingConventions.Standard, null);
ILGenerator ctor1IL = ctor1.GetILGenerator();
FieldInfo[] infos;
infos = enumType.GetFields(BindingFlags.Public | BindingFlags.Static);
//basically for each value in the enumeration an output is created
foreach (FieldInfo fi in infos)
{
 MethodInfo addoutputinfo = tb.BaseType.GetMethod("addoutput",     BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |     BindingFlags.Static);
 ctor1IL.Emit(OpCodes.Ldarg_0);
 //something like this ? seems there's a syntax error 
 ctor1IL.Emit(OpCodes.Ldobj,fi.GetValue(null))  
 ctor1IL.Emit(OpCodes.Call, addoutputinfo);
}

你能提供一个吗?好的,请再次回顾OP,谢谢用C写代码,然后看看ILDASM生成了什么@用户1296193,你能提供你尝试得到的c#等价物吗?addoutput(Enum.EnumValue1);addoutput(Enum.EnumValue2)。。。。