1

According to page 196 of the CLR ECMA standard doc, the following is the MSIL grammar for defining a class property getter.

.get CallConv Type [ TypeSpec ‘::’ ] MethodName ‘(’ Parameters ‘)’

.get specifies the getter for this property. The TypeSpec defaults to the current type. Only one getter can be specified for a property. To be CLS-compliant, the definition of getter shall be marked specialname.

Note the bolded section above, and the fact that TypeSpec '::' is within []

So I take that to mean I should be able to do this inside a class:

   .property instance int32 'Top'()
   {
     .get instance int32  get_Top()
     .set instance void   set_Top(int32)
   }

However, ilasm doesn't accept it, complaining:

Error: unresolved global member ref 'get_Top' Error: unresolved global member ref 'set_Top'

It only accepts Stack`1::get_Top():

The full property + methods look like:

.class public ansi Stack`1<T>  
{
   .field public int32 'top'

   .property instance int32 'Top'()
   {
     .get instance int32 Stack`1::get_Top()
     .set instance void  Stack`1::set_Top(int32)
   }

   .method public hidebysig specialname instance int32 get_Top() cil managed
   {
     ldarg.0
     ldfld int32 class Stack`1<!T>::'top'
     ret
   }

   // snip
}

Am I misunderstanding the spec?

codenheim
  • 20,467
  • 1
  • 59
  • 80

0 Answers0