Skip to content

Interceptors #456

Description

@ufcpp

C# 12 時点で preview feature。オプション指定必須。

ufcpp-live/UfcppLiveAgenda#74 (comment)

usingSystem.Runtime.CompilerServices;varc=newC();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"classC{publicvoidInterceptableMethod(intparam){Console.WriteLine($"interceptable {param}");}}// generated codestaticclassD{[InterceptsLocation(@"[full path to Program]\Program.cs",4,3)]publicstaticvoidInterceptorMethod(thisCc,intparam){Console.WriteLine($"interceptor {param}");}[InterceptsLocation(@"[full path to Program]\Program.cs",5,3)][InterceptsLocation(@"[full path to Program]\Program.cs",6,3)]publicstaticvoidOtherInterceptorMethod(thisCc,intparam){Console.WriteLine($"other interceptor {param}");}}
namespaceSystem.Runtime.CompilerServices;[Diagnostics.Conditional("CompileTimeOnly")][AttributeUsage(AttributeTargets.Method,AllowMultiple=true)]internalsealedclassInterceptsLocationAttribute:Attribute{publicInterceptsLocationAttribute(stringpath,intlineNumber,intcolumnNumber){_=path;_=lineNumber;_=columnNumber;}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions