读书人

请教这两句IL代码用emit怎么写呢

发布时间: 2013-01-26 13:47:04 作者: rapoo

请问这两句IL代码用emit如何写呢?
IL代码如下


newobj instance void [mscorlib]System.Guid::.ctor(string)
call instance void [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Guid>::.ctor(!0)



这样写会有报错。

Type propertyType = propertyInfo.PropertyType;
Type nullableUnderlyingType = Nullable.GetUnderlyingType(propertyType);
Type propertyBaseType = nullableUnderlyingType != null ? nullableUnderlyingType : propertyType;

il.Emit(OpCodes.Newobj, propertyBaseType.GetConstructor(new Type[] { typeof(string) }));
if (nullableUnderlyingType != null)
il.Emit(OpCodes.Call, propertyType.GetConstructor(Type.EmptyTypes));

[解决办法]
目测你这il代码是两个构造函数吗?
用refrector.exe工具反编译一下,可以生成C#或VB.net代码

读书人网 >C#

热点推荐