This issue will aim to C# experimental feature "interceptors" - to implement a method that will be replaced with new one in runtime, to change callsites.
using System;
using System.Runtime.CompilerServices;
using Test;
BaseType obj = new DerivedType();
obj.Do();
namespace Test
{
file static class DerivedType_Intercepted
{
[InterceptsLocation("<file-path-here>", 6, 5)]
public static void Do(this BaseType @this) => Console.WriteLine("intercepted.");
}
}
namespace Test
{
internal class BaseType
{
public virtual void Do() => Console.WriteLine(nameof(BaseType));
}
internal sealed class DerivedType : BaseType
{
public override void Do() => Console.WriteLine(nameof(DerivedType));
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
file sealed class InterceptsLocationAttribute(string filePath, int line, int character) : Attribute
{
public string FilePath { get; } = filePath;
public int Line { get; } = line;
public int Character { get; } = character;
}
}
This will make the result to be "intercepted." instead of "DerivedType".
This issue will aim to C# experimental feature "interceptors" - to implement a method that will be replaced with new one in runtime, to change callsites.
This will make the result to be "intercepted." instead of "DerivedType".
For more information please visit this link.
To-do list:
CachedAttribute
InterceptorMethodCallerAttribute
InterceptsLocationAttribute
string filePath, int line, int character
Constructorint version, string data
internal
instead ofpublic
to avoid conflictionCachedMethodGenerator
CachedMethodSyntaxRewriter
grid
properties that can be replaced with cached onesthis
referencesthis
parameter if the target method is an instance methodTypeName parameter
ref readonly
= defaultValue
ref
modifiers:ref readonly ReturnType
Method<T1, T2>
where T : notull, allows ref struct
this
: Append parameterthis ReferenceType @this
this
: Append parameterthis ValueType @this
ref
modifier:this ref ValueType @this
scoped
modifier:this scoped RefStructType @this
[InterceptorInstanceTypes]