.net - Looking up FieldRef and FieldDef metadata tokens via Reflection -


i'm working on program pre-compiles bytecode .net assemblies. program .net program - far i've been able use reflection extract needed information including bytecode itself. however, i've run problem implementing translation ldfld.

ldfld , similar instructions have metadata token within encoding references fieldref or fielddef. understand these elements in metadata tables embedded in assembly's pe file. in worst-case have enough information ecma-335 open pe file , myself, that's lot of work , not consistent other information through reflection, prefer lookup via reflection.

however, can't seem find methods on system.reflection.assembly metadata token. (i may have missed it.) can't lookup on more specific assembly because know referencing assembly until see metadata (catch-22.) in fact, noted in comments, don't know assembly field defined in, until examining metadata.

is there way such metadata tokens via reflection?

you didn't find on assembly, because fielddef , fieldref don't belong assembly, belong module (most assemblies have single module, can have more). , module has method want: resolvefield(). use this:

module module = …; int fieldtoken = …; fieldinfo field = module.resolvefield(fieldtoken); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -