.NET Framework Bookmark and Share   
 index > Building Development and Diagnostic Tools for .Net > DynamicILInfo.GetTokenFor
 

DynamicILInfo.GetTokenFor

Just want to make sure I understand for what things I need to get tokens and insert them into the byte code stream I am generating. I believe it is anything that is referenced in the byte code stream that would have a metadata token associated with it. Working from the overloads for the GetTokenFormethod documented in msdn, that would then be any:

byte array,

other dynamic method being invoked,

field being accessed,

assembly-based method being invoked,

type,

string

method on a generic type

Before submitting a custom-generated byte code sequence I would want to resolve the metadata tokens for any of these items. And so if I keep my generated byte code along with a record of those offsets that need to be resolved and the particular metadata needed to resolve them, then I should be able to feed this structure to a resolving method that would call GetTokenForand finalize the byte code stream at the time I am using it to generate an actual dynamic method. This way I could achieve my goal of assembling different configurations of highly factored core byte code streams and avoid having topackage each factored unit into its own callable method. My system alreadydoes this with assembly code and with my own virtual machine byte codes and I would liketo extend it to work with CLI byte codes as well.

Anything you see wrong with this picture? You mentioned in a response to my previous post that it was "dangerous" to hold on to generated byte code streams. Metadata token issues aside, is there something else I should be concerned about?

mclagett

I mentioned it was "dangerous", mainly thinking that keeping the buffer around makes it tempting to misuse it. If you're using it safely, it sounds like your plan will work.

One danger would be if the tokens can be compressed in the IL-byte stream, and if that compression is variable length.I just double checked the ecma spec (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-335.pdf) and ildasm (show code bytes) and that's not the case.

Mike Stall - MSFT

I mentioned it was "dangerous", mainly thinking that keeping the buffer around makes it tempting to misuse it. If you're using it safely, it sounds like your plan will work.

One danger would be if the tokens can be compressed in the IL-byte stream, and if that compression is variable length.I just double checked the ecma spec (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-335.pdf) and ildasm (show code bytes) and that's not the case.

Mike Stall - MSFT
Thank you very much for the reply. You probably won't hear from me any more on this until later this month when I actually get to work on it(at which time I am likley to need a question or two answered).
mclagett

You can use google to search for other answers

Custom Search

More Threads

• CreateDebuggingInterfaceFromVersion returns HR == invalid arg
• COMException "Bad binary signature"
• Best Book on Using .NET for Creating Windows Controls
• Reflection.Emit More Dynamic?
• PropertGet. EvalException. System.Reflection.TargetParameterCountException
• profiler: filter "system calls"
• Bug in ISymUnmanagedDocument.FindClosedLine for nested class?
• .pdb/VS debugger issue
• Debugging my own process
• No type libararies were found in the component