Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

How can I change any type from function signature to object type in IL?

$
0
0
I saw the link below, and want to implement my dynamic IL for making any type to Oject type.
https://blogs.msdn.microsoft.com/davbr/2006/02/27/bug-inspecting-value-type-returns/

My way is below:
1.If a CorElementType is not value type goto end
2.Find the CorElementType's  type string (eg.  ELEMENT_TYPE_BOOLEAN -> L"System.Boolean", ELEMENT_TYPE_I4 -> L"System.Int32"  )
3.Find mdTypeRef from the module token by FindTypeRef with type string.
4.Write IL :  box <mdTypeRef>

Q1: Any problem with my way above?
Q2: How can I judge a CorElementType whether it need box or not  is difficult? 
      I meet an Enumerations argument, and I don't know how to judge his CorElementType and get his mdTypeRef.
Q3: At step2, I need to make a map to change CorElementType to string, then find mdTypeRef by string. 
      It is not elegant, any way more elegant? 
      Can I box all value type with "System.ValueType"'s mdTypeRef directly?

Really appreciate!

Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>