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
精彩评论