首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2013-01-26 
请问这两句IL代码用emit如何写呢?IL代码如下newobj instance void [mscorlib]System.Guid::.ctor(string)c

请问这两句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代码

热点排行