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

事理 2013-01-22 09:42:47
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));
...全文
165 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gxingmin 2013-01-22
  • 打赏
  • 举报
回复
目测你这il代码是两个构造函数吗? 用refrector.exe工具反编译一下,可以生成C#或VB.net代码
事理 2013-01-22
  • 打赏
  • 举报
回复
哈哈,自己搞定了,来个人接分
事理 2013-01-22
  • 打赏
  • 举报
回复
没人会么

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧