Module initializers in C#
After eleven years, this is finally supported by the language in C#9
https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9#support-for-code-generators
Incorrect behavior of the [ModuleInitializer]?
Here is an explanation on github
A module initializer is executed at, or sometime before, first access
to any static field or first invocation of any method defined in the
module.
How can I run a static initializer method in C# before the Main() method?
Simply do the initialization inside a static constructor for Foo
.
From the documentation:
A static constructor is called automatically to initialize the class
before the first instance is created or any static members are
referenced.
Static constructor for the whole assembly
Check Module initializers in C#.
Automatically run code on referenced assembly during startup?? What is this called?
Turns out I was looking for PreApplicationStartMethod! Thanks all!
Related Topics
Write to Windows Application Event Log Without Event Source Registration
Is Enabling Double Escaping Dangerous
Converting File into Base64String and Back Again
How to Keep a .Net Console App Running
Simple Animation Using C#/Windows Forms
How to Get the Directory from a File's Full Path
How to Return a Specific Status Code and No Contents from Controller
.Net Timezoneinfo from Olson Time Zone
Passing an Enum Value as Command Parameter from Xaml
Getting All Controllers and Actions Names in C#
Enable Entity Framework 6 for MySQL (C#) in Winforms of Microsoft Visual Studio 2013
Weak Event Handler Model for Use with Lambdas
Get Value of C# Dynamic Property via String
How to Pronounce "=>" as Used in Lambda Expressions in .Net
Datetime Format to SQL Format Using C#
What Are Best Practices for Using Smtpclient, Sendasync and Dispose Under .Net 4.0