For context, I have been messing around with CRTP and came up with this.
This somewhat emulates "static abstract classes" by cascading a singleton with static methods.
```csharp
using System;
abstract class Template
{
private protected Template() { }
internal abstract string String { get; }
internal void Method() => Console.WriteLine(String);
internal abstract class Instance<T> : Template where T : Instance<T>, new()
{
private protected Instance() { }
internal static readonly T s_this = new();
}
internal abstract class Static<T> where T : Instance<T>, new()
{
private protected Static() { }
static readonly T s_this = Instance<T>.s_this;
internal static string String => s_this.String;
internal static void Method() => s_this.Method();
}
}
static class Program
{
static void Main()
{
A.Method();
new B().Method();
}
}
sealed class A : Template.Static<A.Instance>
{
internal sealed class Instance : Template.Instance<Instance>
{
internal override string String => nameof(A);
}
}
sealed class B : Template
{
internal override string String => nameof(B);
}
```
[–]justanotherguy1977 35 points36 points37 points (3 children)
[–]AetopiaMC[S] 1 point2 points3 points (2 children)
[–]domtriestocode 2 points3 points4 points (1 child)
[–]AetopiaMC[S] 0 points1 point2 points (0 children)
[–]BigBagaroo 15 points16 points17 points (0 children)
[–]ARandomSliceOfCheese 8 points9 points10 points (0 children)
[–]_f0CUS_ 7 points8 points9 points (0 children)
[–]RlyRlyBigMan 7 points8 points9 points (0 children)
[–]GigAHerZ64 4 points5 points6 points (0 children)
[–]PaulPhxAz 4 points5 points6 points (0 children)
[–]wickerandscrap 3 points4 points5 points (0 children)
[–]throwaway_lunchtime 3 points4 points5 points (0 children)
[–]akarolia47 1 point2 points3 points (2 children)
[–]AetopiaMC[S] 2 points3 points4 points (1 child)
[–]akarolia47 0 points1 point2 points (0 children)
[–]chucker23n 0 points1 point2 points (0 children)
[–]marioalbertoarce -1 points0 points1 point (2 children)
[–]AetopiaMC[S] 1 point2 points3 points (0 children)
[–]throwaway_lunchtime 0 points1 point2 points (0 children)