.net - CLR token 可以为零或负数

标签 .net reflection clr cil reflection.emit

某些 .NET 反射方法(例如 Module.ResolveField )接受所谓的标记作为参数。这些标记只是 Int32 数字。我在反汇编程序中只看到正数标记,但是一般来说,整数也可以是负数或零。假设 CLR 代币只是正数是否安全?

最佳答案

它们实际上是无符号数字。来自 MS Partition II,第 22 节(取自 this page):

Metadata items (records in the metadata tables) are addressed by metadata tokens. Uncoded metadata tokens are 4-byte unsigned integers, which contain the metadata table index in the most significant byte and a 1-based record index in the three least-significant bytes

鉴于没有元数据表索引具有最高位设置,因此无需担心将 unsigned int 转换为 int 时会产生溢出或负数数量。

关于.net - CLR token 可以为零或负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21904990/

相关文章:

c# - 在另一个线程中抛出异常时不调用 UnhandledException

.net - 增量/差异备份到 Azure blob

c# - 通过反射或类似方式动态生成属性 getter/setter

c# - 如果我的结构不在 COM Interop 中执行,我应该为我的结构使用 LayoutKind.Auto 吗?

php - 使用字符串获取模型

java - Java有 "is kind of class"的测试方法吗

error-handling - SQL Try-Catch block 可以处理抛出的 CLR 错误吗?

c# - .Net Core 2.0 Windows 服务

C# 对象空检查

c# - 不使用 keystore 的客户端证书