C#:MemberInfo.MetadataToken 跨编译器运行稳定吗? [英] C#: MemberInfo.MetadataToken stable across compiler runs?

查看:34
本文介绍了C#:MemberInfo.MetadataToken 跨编译器运行稳定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们需要一种方法来唯一标识 C# 中的反射元数据对象.反射 API 有一个 MemberInfo.MetadataToken 属性,该属性被记录为完成此任务.但是,没有记录的是,鉴于模块名称、命名空间、声明类型名称和成员名称未更改,在同一模块的下一次构建之后,此令牌是否会相同.

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?

谢谢!米尔科

推荐答案

不,他们不会.元数据标记值取决于程序集中的其他所有内容,以及编译器在输出程序集中生成类型的确切顺序.如果输入代码或项目以任何方式发生变化,那么所有令牌都可能发生变化.

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.

为什么需要这样做?

这篇关于C#:MemberInfo.MetadataToken 跨编译器运行稳定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆