Property Signatures
Property signatures hold the information about whether a property is static or instance, how many parameters the getter/setter methods and the property's return type.
From the Ecma 335, Partition II, page 157:
A PropertySig is indexed by the Property.Type column. It captures the type information for a Property – essentially, the signature of its getter method:
the number of parameters supplied to its getter method
the base type of the Property (the type returned by its getter method)
type information for each parameter in the getter method (that is, the index parameters)
Note that the signatures of getter and setter are related precisely as follows:
- The types of a getter’s paramCount parameters are exactly the same as the first paramCount
parameters of the setter - The return type of a getter is exactly the same as the type of the last parameter supplied to the
setter
The syntax diagram for a PropertySig looks like this:
The first byte of the Signature holds bits for HASTHIS and PROPERTY. These are OR’d together.
Type specifies the type returned by the Getter method for this property. Type is defined in §23.2.12.
ParamCount is an integer that holds the number of index parameters in the getter methods (0 or more). (ParamCount counts just the method parameters – it does not include the method’s base type of the Property)
IMAGE_CEE_CS_CALLCONV_PROPERTY = 0x08
IMAGE_CEE_CS_CALLCONV_HASTHIS = 0x20 - so and instance property will be 0x28
Example 37: Static Read-only string Property
C# Code:
private static string stringProperty;
public static string StringProperty
{
get { return stringProperty; }
}
ILDasm Property Information:
The signature is: 08 00 0e
0x08 = IMAGE_CEE_CS_CALLCONV_PROPERTY
0x00 = ParamCount
0x0e = ELEMENT_TYPE_STRING
This tells us it is a static property that is a string type
Example 38: Instance Read/Write class property
C# Code:
private TestClass testClassObj;
public TestClass TestClassProp
{
get { return testClassObj; }
set { testClassObj = value; }
}
ILDasm Property Information
The signature is: 28 00 12 08
0x28 = IMAGE_CEE_CS_CALLCONV_PROPERTY and IMAGE_CEE_CS_CALLCONV_HASTHIS
0x00 = ParamCount
0x12 = ELEMENT_TYPE_CLASS
0x08 = TypeDefRefEncoded Token
0x08 is a compressed integer of 8 - which is the same compressed or uncompressed
The TypeDefOrRefEncoded token is a TypeDef and a RID of 2, which is the record SignatureUtility.TestClass in the TypeDef table
This tells us the property is an instance property with no parameters and of the type SignatureUtility.TestClass.
Example 39: Instance Read/Write Indexer property
C# Code:
private Dictionary<string, string> list = new Dictionary<string, string>();
public string this[string name]
{
get { return list[name]; }
set { list[name] = value; }
}
ILDasm Property Information:
The signature is: 28 01 0e 0e
0x28 = IMAGE_CEE_CS_CALLCONV_PROPERTY and IMAGE_CEE_CS_CALLCONV_HASTHIS
0x01 = ParamCount = 1
0x0e = ELEMENT_TYPE_STRING
0x0e = ELEMENT_TYPE_STRING
This tells us it is an instance property, that has 1 parameter of type string and returns a string (is a property type string).
Example 40: Automatic Implemented Property
This is an example of the property syntax in C# 3.5, where you don't specify any property bodies.
C# Code:
public string Net30Prop { get; set; }
ILDasm Property Information:
The signature is: 28 00 0e
0x28 = IMAGE_CEE_CS_CALLCONV_PROPERTY and IMAGE_CEE_CS_CALLCONV_HASTHIS
0x00 = ParamCount
0x0e = ELEMENT_TYPE_STRING
This tells us it is a static property that is a string type
Notes to be provided soon:
- LocalVarSig
- More detail on the Param decoding
- More detail on the CustomMod decoding
- More detail on ReturnType decoding
- StandAloneMethodSig