Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It <em>seems</em> to me that even though you can define a .cctor on an interface in CLI, it is kind of useless. Partition I, § 8.9.5 states:</p> <blockquote> <p>If marked BeforeFieldInit then the type‘s initializer method is executed at, or sometime before, first access to any static field defined for that type. If not marked BeforeFieldInit then that type‘s initializer method is executed at (i.e., is triggered by): first access to any static field of that type, or first invocation of any static method of that type, or first invocation of any instance or virtual method of that type if it is a value type or first invocation of any constructor for that type. <strong>Execution of any type's initializer method will not trigger automatic execution of any initializer methods defined by its base type, nor of any interfaces that the type implements</strong></p> </blockquote> <p>(emphasis mine) Which means the type initializer on an interface does not get called automatically at all. If you want it to be called, you (IMHO) need to call it explicitly in all implementing classes, like this:</p> <pre><code>.method private static specialname rtspecialname void .cctor() { ldtoken IInterface callvirt instance valuetype [mscorlib]System.RuntimeTypeHandle [mscorlib]System.Type::get_TypeHandle() call void [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::RunClassConstructor(valuetype [mscorlib]System.RuntimeTypeHandle) ldstr "Class static cctor" call void [mscorlib]System.Console::WriteLine(string) ret } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload