I have many classes in an assembly that I can't or don't want to modify. At some point of runtime, I want to know which of them have already been "initialized": static initializer has run.
Is there a way to do it with reflection or something else?
For information, not every class in an assembly is initialized when the assembly is loaded. This can be easily observed with this piece of code:
public static class Foo
{
static Foo() { MainClass.Value = "Something"; }
public static void DoSomething() { Thread.Sleep(100); }
}
public static class MainClass
{
public static string Value = "Nothing";
public static void Main()
{
Console.WriteLine(Value);
Foo.DoSomething();
Console.WriteLine(Value);
}
}
Displays:
Nothing
Something
Aucun commentaire:
Enregistrer un commentaire