ltrzesniewski / InlineIL.Fody

Inject arbitrary IL code at compile time.
MIT License
241 stars 17 forks source link
fody msil

InlineIL.Fody Logo

Build NuGet package GitHub release License

This is an add-in for Fody which lets you inject arbitrary IL into your assembly at compile time.

The following C# code Is compiled to the following IL
```C# using static InlineIL.IL.Emit; public static class Example { public static void ZeroInit(ref T value) where T : struct { Ldarg(nameof(value)); Ldc_I4_0(); Sizeof(typeof(T)); Unaligned(1); Initblk(); } } ``` ``` .method public hidebysig static void ZeroInit ( !!T& 'value' ) cil managed { .maxstack 8 IL_0000: ldarg.0 IL_0001: ldc.i4.0 IL_0002: sizeof !!T IL_0008: unaligned. 1 IL_000b: initblk IL_000d: ret } ```

Installation

See Fody usage for general guidelines, and Fody configuration for additional options.

Usage

Call static methods of the InlineIL.IL.Emit class to emit IL instructions. That's it. :wink:

A few more things which are good to know:

Methods

Types

Configuration

The <InlineIL /> element in FodyWeavers.xml accepts the following attributes:

Examples