using System.Runtime.CompilerServices;
var c = new C();
c.InterceptableMethod(1); // (L1,C1): prints "interceptor 1"
c.InterceptableMethod(1); // (L2,C2): prints "other interceptor 1"
c.InterceptableMethod(2); // (L3,C3): prints "other interceptor 2"
c.InterceptableMethod(1); // prints "interceptable 1"
class C
{
public void InterceptableMethod(int param)
{
Console.WriteLine($"interceptable {param}");
}
}
// generated code
static class D
{
[InterceptsLocation(@"[full path to Program]\Program.cs", 4, 3) ]
public static void InterceptorMethod(this C c, int param)
{
Console.WriteLine($"interceptor {param}");
}
[InterceptsLocation(@"[full path to Program]\Program.cs", 5, 3)]
[InterceptsLocation(@"[full path to Program]\Program.cs", 6, 3)]
public static void OtherInterceptorMethod(this C c, int param)
{
Console.WriteLine($"other interceptor {param}");
}
}
C# 12 時点で preview feature。オプション指定必須。
https://github.com/ufcpp-live/UfcppLiveAgenda/issues/74#issuecomment-1633665906