GetMember by MetadataToken

2019-09-04 05:21发布

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);

标签: c# reflection
1条回答
甜甜的少女心
2楼-- · 2019-09-04 06:10

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

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

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

查看更多
登录 后发表回答