Property Declaration
The ILAsm syntax for a property declaration is as follows:
.property <flags> <ret_type> <name>(<param_type>[,<param_type>*] ) [ <const_decl> ] { <method_semantics_decl>* }
where
<method_semantics_decl> ::= <semantics> <method_ref> <semantics> ::= .set .get .other <const_decl> ::= = <const_type> [ ( <value> ) ]
The <ret_type> and the sequence of <param_type> nonterminals define the property’s signature. <semantics> defines the type of the associated methods: .set for the setter, .get for the getter, and .other for any other method defined for this property. The optional <const_decl> is the declaration of the property’s default value, similar to that of a field or a method parameter. The parent of the property is the class in whose scope the property is declared, as is the case for other class members (fields, methods, and events).
Now, as an exercise, let’s declare a simple property:
.class public A { .field private unsigned int32 theTally = int32(0xFFFFFFFF) // Constructor: set Tally to 0xFFFFFFFF (not used yet) .method public void .ctor() { ldarg.0 call instance void [mscorlib]System.Object::.ctor() ldc.i4 0xFFFFFFFF ldarg.0 stfld unsigned int32 A::theTally ret } // Setter: set Tally to Val if Val is not 0xFFFFFFFF .method public void set_Tally(unsigned int32 Val) { ldarg.1 ldc.i4 0xFFFFFFFF beq.s Return ldarg.1 ldarg.0 stfld unsigned int32 A::theTally Return: ret } // Getter: return the value of Tally .method public unsigned int32 get_Tally() { ldarg.0 ldfld unsigned int32 A::theTally ret } // Other method: reset the value of Tally to 0xFFFFFFFF .method public void reset_Tally() { ldc.i4 0xFFFFFFFF ldarg.0 stfld unsigned int32 A::theTally ret } .property unsigned int32 Tally(unsigned int32) = int32(0xFFFFFFFF) { .set instance void A::set_Tally(unsigned int32) .get instance unsigned int32 A::get_Tally() .other instance void A::reset_Tally() } } // The end of class A