No description
Find a file
2026-04-02 21:28:34 +02:00
.github/workflows CI: set write permission 2026-02-24 11:42:12 +01:00
Experiments Fix lints 2026-02-24 11:18:14 +01:00
Weberknecht Replace returns util 2026-04-02 21:26:12 +02:00
Weberknecht.Test Make TestException sealed (lint) 2026-04-02 21:28:34 +02:00
.gitignore initial commit 2026-02-02 21:29:00 +01:00
Directory.Build.props Fix test with exception table 2026-02-24 11:27:28 +01:00
global.json Unit tests 2026-02-24 10:50:00 +01:00
README.md Unit tests 2026-02-24 10:50:00 +01:00
Weberknecht.slnx Unit tests 2026-02-24 10:50:00 +01:00

build workflow status

Weberknecht

Complements the System.Reflection API with full IL inspection capabilities at runtime.

Usage

Everything is still work in progress.

int b = 2;

var method = MethodReader.Read((in int a) =>
{
    return a + b + TestClass.CreateInt();
});

Console.WriteLine(method);

Prints (Debug build):

Int32 Method(in Int32& a)
        nop
        ldarg.1
        ldind.i4
        ldarg.0
        ldfld Int32 b
        add
        call Int32 CreateInt()
        add
        stloc.0
        br.s L0001
L0001:  ldloc.0
        ret

A more complex example

int b = 2;

var method = MethodReader.Read((in int a) =>
{
    int temp = a + b;
    unsafe
    {
        fixed (int* x = &a)
        {
            Console.WriteLine($"{(nint)x:016x} = {*x}");
        }
    }
    return temp + TestClass.CreateInt();
});

Console.WriteLine(method.ToString(debugInfo: true));

Release build output:

Int32 Method(in Int32& a)
.locals (Int32* x, pinned Int32&, DefaultInterpolatedStringHandler)
  @ _/Experiments/Program.cs:7:5
        ldarg.1
        ldind.i4
        ldarg.0
        ldfld Int32 b
        add
  @ _/Experiments/Program.cs:9:5
        ldarg.1
        stloc.1
  @ _/Experiments/Program.cs:10:16
        ldloc.1
        conv.u
        stloc.0
  @ _/Experiments/Program.cs:12:13
        ldloca.s 2
        ldc.i4.3
        ldc.i4.2
        call Void .ctor(Int32, Int32)
        ldloca.s 2
        ldloc.0
        ldstr "016x"
        call Void AppendFormatted[IntPtr](IntPtr, System.String)
        ldloca.s 2
        ldstr " = "
        call Void AppendLiteral(System.String)
        ldloca.s 2
        ldloc.0
        ldind.i4
        call Void AppendFormatted[Int32](Int32)
        ldloca.s 2
        call System.String ToStringAndClear()
        call Void WriteLine(System.String)
  @ _/Experiments/Program.cs:<hidden>
        ldc.i4.0
        conv.u
        stloc.1
  @ _/Experiments/Program.cs:15:5
        call Int32 CreateInt()
        add
        ret