I’m definitely not the first person to think of this, but I like it in a cheating kind of way.
Is the typeof(subtract) == typeof(const_true)
comparison optimized away by the compiler? If not, I can see it adding quite a bit of overhead
Typeof will resolve at compile time, as opposed to .GetType()
No, probably not. The CLR’s JIT compiler reuses a single jitted method for each generic method, unless one of the generic type parameters is a value type.
I do not understand the purpose of this?
Please don’t do this. Generics aren’t templates. There are about a hojillion better ways of accomplishing this in C#, and none of them abuse generics and interfaces to create fake templates. (In fact, that’s why they’re “better”.)
Also, marker interfaces in C# are usually viewed as a “code smell”, and this is a large part of the reason why.