4767

GetMember by MetadataToken

Question:

What is the proper way of getting a member of a type using a metadata token of that member (with reflection)?

I've tried:

MemberInfo mi = type.GetMembers(bindingFlags).FirstOrDefault(m => m.MetadataToken == metadataToken);

Answer1:

The <em>Module</em> class provides a set of <em>Resolve</em> methods that can find the member, e.g.

MemberInfo mi = type.Module.ResolveMember(metadataToken);

Edit: <em>ResolveMember</em> cannot resolve properties and events, so the originally suggested approach has to be used.

Recommend

  • Is there a way to access __dict__ (or something like it) that includes base classes?
  • C# Reflection: Get info for all members of class and base classes
  • Getting the method name of a task
  • How to use reflection to get just the object instance's public properties?
  • C# Reflection SetValue() can not find set accessor
  • How to cast to a type in C#
  • Finding a user through the GroupPrincipal
  • C#: MemberInfo.MetadataToken stable across compiler runs?
  • Writing to csv with for loops
  • Change text of “Cancel” button on a UISearchBar using Monotouch?
  • Linq to SQL and SQL Injection
  • Getting ORA-01861 - Literal does not match format string on SQLPlus Only
  • Filling out Object Properties with default values Recursive
  • How to access the database from the api controller?
  • How can I force LINQ to SQL to perform an INNER JOIN on a nullable foreign key?
  • How can I write a where clause in SQL to filter a DATETIME column by the time of day?
  • Upgrade to g++ 4.7 (with c++11 support): any ABI incompatibility?
  • how to show filtered JSON data from two different key values in react native
  • How to handle images sent by a mobile device?
  • d3 v4 drag and drop with TypeScript
  • JSON response opens as a file, but I can't access it with JavaScript
  • Play WS (2.2.1): post/put large request
  • DomPDF {PAGE_NUM} not on first page
  • Lost migrations and Azure database is now out of sync
  • Deselecting radio buttons while keeping the View Model in synch
  • Getting last autonumber in access
  • JavaScriptCore crash on iOS9
  • Importing jscolor library in angular 2
  • QuartzCore.framework for Mono Develop
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Arrays break string types in Julia
  • How to format a variable of double type
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?