C#C
C#3y ago
CyberBotX

❔ How to call static virtual interface method without completely reimplementing in derived class

This mainly pertains to generic math in C# 11 / .NET 7, but say I have a minimum of something like this:
interface ITest
{
    static virtual void Test() => Console.WriteLine("Test");
}
class Testing : ITest
{
}

I cannot find a way to call the Test method from ITest without just redefining it entirely in Testing, even if said redefining is 100% identical to the interface's code (which seems terrible to me). Obviously I can't call ITest.Test() because it is an interface and not a class, and I can't call Testing.Test() because the method technically doesn't exist on Testing. The only workaround I've found is doing something like void RunTest<T>() where T : ITest => T.Test(); and calling it via RunTest<Testing>(); but that doesn't work for my purposes. I also can't define the method in Testing as public static void Test() => ITest.Test(); for the same reason as being unable to just call the last part due to it being on an interface.
Was this page helpful?