Home

Awesome

InlineIL.Fody <picture><source media="(prefers-color-scheme: dark)" srcset="icon-dark.png"><img src="icon.png" align="right" alt="Logo"></picture>

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. <br clear="right" />

<table> <tr> <th width="415px">The following C# code</th> <th width="415px">Is compiled to the following IL</th> </tr> <tr> <td>
using static InlineIL.IL.Emit;

public static class Example
{
    public static void ZeroInit<T>(ref T value)
        where T : struct
    {
        Ldarg(nameof(value));
        Ldc_I4_0();
        Sizeof(typeof(T));
        Unaligned(1);
        Initblk();
    }
}
</td> <td>
.method public hidebysig static void ZeroInit
    <valuetype .ctor
      ([System.Runtime]System.ValueType) T> (
    !!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
}
</td> </tr> </table>

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