6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Mainメソッドよりも前にコードを実行する

Posted at

参考

この記事は、以下の動画を参考にしています。
詳しくは、動画をご覧ください。

ModuleInitializerAttribute

ModuleInitializer属性

ModuleInitializer属性をメソッドに付けることで、そのメソッドを含むアセンブリの他のコードよりも前に、そのメソッドを実行できる。

internal class BootStrapper
{
    [ModuleInitializer]
    internal static void Init()
    {
        Console.WriteLine(@"Bootstrapping...");
    }
}

ModuleInitializer属性を付けられるメソッドの条件

  • クラスメソッド(static
  • 戻り値はない(void
  • 引数なし
  • アクセス指定がinternalまたはpublicになる
  • ModuleInitializer属性が付くメソッドが、複数あってもかまわない
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?