public class MyClass : ISelfReferenceable<Guid>
{
public Guid Id {get;set;}
public Guid? ParentId {get;set;}
}
public interface ISelfReferenceable<TId>
{
TId Id {get;set;}
TId? ParentId {get;set;}
}
Can anyone explain to me why the above does not work?
It shouts Compiler Error CS0738
'type name' does not implement interface member 'member name'. 'method name' cannot implement 'interface member' because it does not have the matching return type of ' type name'.
on MyClass.ParentId, saying that it doesn't implement ISelfReferenceable.ParentId, unless I change MyClass.ParentId from Guid? to Guid.
Currently, I get around this by using two generic types, one for Id and another for ParentId, or simply make ParentId Guid instead of Guid?.
Is this the right approach and is there a better way of doing this?