Skip to content
Adds a module initializer to an assembly.
Branch: master
Clone or download
Latest commit 930b4ad Mar 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
AssemblyToProcess
ModuleInit.Fody
ModuleInit
Tests
.editorconfig
.gitattributes
.gitignore
Directory.Build.props
ModuleInit.sln
ModuleInit.sln.DotSettings
appveyor.yml
license.txt
package_icon.png
readme.md

readme.md

Chat on Gitter NuGet Status

This is an add-in for Fody

Icon

Adds a module initializer to an assembly.

Usage

See also Fody usage.

NuGet installation

Install the ModuleInit.Fody NuGet package and update the Fody NuGet package:

PM> Package Fody
PM> Install-Package ModuleInit.Fody

The Install-Package Fody is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.

Add to FodyWeavers.xml

Add <ModuleInit/> to FodyWeavers.xml

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <ModuleInit/>
</Weavers>

What it does

Based on Einar Egilsson's suggestion using cecil to create module initializers [http://tech.einaregilsson.com/2009/12/16/module-initializers-in-csharp/]

Finds a class, in the target assembly, named 'ModuleInitializer' with the following form.

public static class ModuleInitializer
{
    public static void Initialize()
    {
        //Init code
    }
}

Injects the following code into the module initializer of the target assembly. This code will be called when the assembly is loaded into memory

static <Module>()
{
    ModuleInitializer.Initialize();
}

Icon

Icon courtesy of The Noun Project

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.