Method invocation on a struct?

According to the CIL spec the this pointer is passed by reference / as managed pointer. As Binary Worrier assumed this is a CIL feature.

Instance and virtual methods of
classes shall be coded to expect a
reference to an instance of the class
as the this pointer. By contrast,
instance and virtual methods of value
types shall be coded to expect a
managed pointer (see Partition I) to
an unboxed instance of the value type.

The CLI shall convert a boxed value
type into a managed pointer to the
unboxed value type when a boxed value
type is passed as the this pointer to
a virtual method whose implementation
is provided by the unboxed value type.

So from a high-level perspective a call to an instance method of a reference type (class) looks like this:

MyClass myClass = MyClass_Constructor();

MyClass_MyInstanceMethod(myClass, myFirstParameter);
//                       ^
//                       The "this" argument

And a call to an instance method of a value type (struct) like this:

MyStruct myStruct = MyStruct_Constructor();

MyStruct_MyInstanceMethod(ref myStruct, myFirstParameter);
//                        ^
//                        The "this" argument

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)