开发者

Invoke default parameterless valuetype constructor via Reflection.Emit

Is this at all possible, given Type.GetConstructors() will not return such a constructor?

I have looked at this question but it still does not solve the problem.

Example:

How to emit default(Nullable<int>) or default(Guid)?

PS: I am not interested in workarounds. I can guess a few, but it would b开发者_JS百科e impossible for me to integrate them directly into my compiler without substantial modifications.


Grrr. Found my answer.

You use OpCodes.Initobj :)

http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.initobj(VS.100).aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜