gpt4 book ai didi

c# - IL ".custom instance void [attribute] = (...)"是什么意思?

转载 作者:太空宇宙 更新时间:2023-11-03 17:29:38 25 4
gpt4 key购买 nike

当我对参数使用 params 关键字时,我在 IL 中找到了这一行。我从中了解到,调用了 ParamArrayAttribute 类的构造函数,但我不明白 01 00 00 00 是什么意思。

.custom instance void [mscorlib]System.ParamArrayAttribute::.ctor() = (
01 00 00 00
)

最佳答案

请参阅 C# specification (version 6) defined in ECMA-335 的 II.21 节:

Custom attributes are declared using the directive .custom, followed by the method
declaration for a type constructor, optionally followed by a Bytes in parentheses:
CustomDecl ::=
Ctor [ ‘=’ ‘(’ Bytes ‘)’ ]

Bytes 段的格式在 II.23.3 节中定义:

CustomAttrib starts with a Prolog – an unsigned int16, with value 0x0001.
...
Next is a description of the optional “named” fields and properties. This starts with
NumNamed – an unsigned int16 giving the number of “named” properties or fields that
follow. Note that NumNamed shall always be present. A value of zero indicates that there
are no “named” properties or fields to follow (and of course, in this case, the
CustomAttrib shall end immediately after NumNamed).

VI.B.3 节中提供了各种自定义属性的示例。

对于ParamArrayAttribute,前两个字节(01 00)是Prolog(小端格式),最后两个字节 (00 00) 是 NumNamed(0 = 无参数)。

关于c# - IL ".custom instance void [attribute] = (...)"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54253495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com