I have quite a sizeable static constructor for one of my classes, and was wanting to refactor it to encapsulate various bits of the initialization within static functions.
One of the things this static constructor does a lot of is initialize the values of static readonly fields. However, when I try to move these parts into functions, obviously the compiler wont let me as these can only be set in the static constructor. This makes sense as it doesn't know that I only intend to call these functions from my static constructor.
Is there any way around this? e.g. is there some sort of attribute I can put on the functions to tell the compiler the functions are only to be called from the static constructor?
You can define local functions inside a static constructor;
The C# compiler will turn those local functions into static methods, with unpronounceable names.