You cannot override a general method with a specific implementation; this is not how generics work. The Extended class should be able to handle GetSomething<int>() calls, for example.
In other words, the signature for the overriding method must be identical to the method that it overrides. By specifying a specific general implementation of the method, you change its signature.
Consider using this approach:
public override T GetSomething<T>() { if (typeof(T) == typeof(string)) return string.Empty; return base.GetSomething<T>(); }
Note that JIT should optimize the condition when compiling a specific instance of this method. (If this is not the case, then this is not a very good JIT!)
(The syntax of your redefinition is technically correct, but not suitable for other reasons. For example, you cannot use the string keyword as the name of a general parameter. And if you could, t do what you want and not compile, because the compiler cannot find method with this signature in supertype.)
cdhowie
source share