C#: MemberInfo.MetadataToken stable across compile

2019-08-02 09:00发布

In our application, we need a way to uniquely identify reflection metadata objects in C#. Reflection API has a MemberInfo.MetadataToken property, which is documented to fulfil this task. However, what isn't documented, is whether this token will be the same after the next build of the same module, given that module name, namespace, declaring type name, and member name are unchanged.

Does anyone know about the details of implementation of this?

Thanks! Mirko

标签: c# reflection
1条回答
甜甜的少女心
2楼-- · 2019-08-02 09:40

No, they won't be. The metadata token value is dependant on everything else in the assembly, and the exact order which the compiler generates types in the output assembly. If the input code or project changes in any way whatsoever, then all the tokens could change.

Why do you need to do this?

查看更多
登录 后发表回答