There are two things - first, your example implementation is not correct. It will raise a StackOverflowException
if you try to get derivedType
(since it's returning itself). In general, a setter would not be required here:
public interface ISomeInterface
{
int SomeMethod(int x);
string DerivedType {get;}
}
public class DerivedClass : ISomeInterface
{
public int DomeMethod (int x) {...};
public string DerivedType
{
get {return "derivedType"; }
}
}
That being said, there is no way to force the implementer to do this correctly. If you want to guarantee that the name will be correct, you could just use reflection instead of putting this into the interface (object.GetType().Name
).