I have the following base classes
The non-generic:
public abstract class Foo
{
public abstract bool DoMagic(string str1, string str2);
}
The generic class, inheriting from the non-generic:
public abstract class Foo<T> : Foo
{
public abstract bool DoMagic(T t1, T t2);
}
Now I want to implement this class
public class FooNumeric : Foo<int>
{
public override bool DoMagic(string str1, string str2) => true;
public override bool DoMagic(int int1, int int2) => true;
}
Everything works as excepted as you can see here:
https://dotnetfiddle.net/kWQUl9
Now I would like to not use int as the generic constraint but instead string.
public class FooString : Foo<string>
{
public override bool DoMagic(string str1, string str2) => true;
//public override bool DoMagic(string int1, string int2) => true;
}
But I can't seem to satisfy the compiler and I keep getting the error
'FooString' does not implement inherited abstract member 'Foo.DoMagic(string, string)'
https://dotnetfiddle.net/rfncTE
I have tried a couple of things, but to no success.
Is this possible?
Solutions I know that could fix this
Use the non-generic class on
FooStringCan't do this because
Foo<T>contains many more generic methods and I have this overlapping on only one occasion.Rename the method
if possible I would like to stick to the names.