C# IL“.custom instance void[attribute]=(…)”是什么意思?

C# IL“.custom instance void[attribute]=(…)”是什么意思?,c#,parameters,cil,C#,Parameters,Cil,当我使用params关键字作为参数时,我在IL中找到了这一行。我从中了解到,调用了ParamArrayAttribute类的构造函数,但我不理解01 00的含义 .custom instance void [mscorlib]System.ParamArrayAttribute::.ctor() = ( 01 00 00 00 ) 当用于修饰成员时,属性可能包含将发送到属性构造函数的初始化参数 比如说 [DataMember(EmitDefaultVal

当我使用params关键字作为参数时,我在IL中找到了这一行。我从中了解到,调用了ParamArrayAttribute类的构造函数,但我不理解01 00的含义

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

当用于修饰成员时,属性可能包含将发送到属性构造函数的初始化参数

比如说

[DataMember(EmitDefaultValue = true)]
public int Property { get; set; }
编译为

.custom instance void
[System.Runtime.Serialization]System.Runtime.Serialization.DataMemberAttribute::.ctor() = 
( 01 00 01 00 54 02 10 45 6D 69 74 44 65 66 61 75 6C 74 56 61 6C 75 65 01 )
您看到的字节码序列对应于EmitDefaultValue参数的初始化

就你而言

01 00 00 00

未向属性构造函数传递任何参数时使用的字节序列。

用于修饰成员时,属性可能包含将发送到属性构造函数的初始化参数

比如说

[DataMember(EmitDefaultValue = true)]
public int Property { get; set; }
编译为

.custom instance void
[System.Runtime.Serialization]System.Runtime.Serialization.DataMemberAttribute::.ctor() = 
( 01 00 01 00 54 02 10 45 6D 69 74 44 65 66 61 75 6C 74 56 61 6C 75 65 01 )
您看到的字节码序列对应于EmitDefaultValue参数的初始化

就你而言

01 00 00 00

未向属性构造函数传递任何参数时使用的字节序列。

请参阅:

字节段的格式见第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=无参数。

请参阅:

字节段的格式见第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=无参数