今天学习设计模式中的单例模式,无意间发现了这个标志BeforeFieldInit。
于是简单地搜索了一下,总结出如下内容。
The C# specification states:
The static constructor for a class executes at most once in a given application domain. The execution of a static constructor is triggered by the first of the following events to occur within an application domain:
* An instance of the class is created.
* Any of the static members of the class are referenced.
The CLI specification (ECMA 335) states in section 8.9.5:
- A type may have a type-initializer method, or not.
- A type may be specified as having a relaxed semantic for its type-initializer method (for convenience below, we call this relaxed semantic BeforeFieldInit)
- 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 Befor