I am sure if the Title is explainatory or not, but I need some help understanding the concept.
We have class (reference types) that has method table associated with Type object. In addition to the method tables, the type object also contains all the static fields, type obj pointer and sync block index.
CLR refers to this method table when calling methods on instance of a reference type.
Method table contains the IL for a particular method that is used to change the state of instance fields.
Similarly we can define methods for a structs (value types).
At runtime, when a method is called on a value type, from where does the CLR refer to the IL of the method being called on the instance of the value type.
struct A
{
// for Immutability of value type
public readonly int a;
public void MethodOnValueType()
{
// Some code here
}
}
Where does CLR refer to find the IL for the method named "MethodOnValueType"?
Is there any Type Object for the value type in the managed heap?
I am sure for the case of reference types but confused for value types.
Thanks.
Methods on value-types do not support polymorphism (except for the methods inherited from object, which are executed differently depending on whether they have been overridden): the call is a static call (not a virtual call). Basically, the "what method" part of the call information is resolved by the compiler and burned into the IL. It is then the job of the JIT to connect that call to the final method code.
There is no object-header etc on a value-type.
You can get a Type object for value-types, but that is not really related to method-call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With