KyouyamaKazusa0805 / Sudoku

A sudoku solver using brute forces and logical techniques.
https://t.sudoku-studio.wiki
MIT License
114 stars 28 forks source link

[Feature] Cached interceptor #739

Closed KyouyamaKazusa0805 closed 3 weeks ago

KyouyamaKazusa0805 commented 3 weeks ago

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".

For more information please visit this link.


To-do list:

KyouyamaKazusa0805 commented 3 weeks ago

Finish for the first phase.