I have the following interface I want to implement in a class:
public interface IAgro {
AgroState agroState { get; }
}
The problem is that instead of implementing AgroState in the class using the interface I want my property to implement a different class which inherits from AgroState
public class E1_AgroState : AgroState
{
...
}
public class BasicWalkingEnemy : Entity, IAgro
{
public E1_AgroState agroState { get; }
}
This is something I am used to do in Swift with protocols, for example, but C# compiler complains with
'BasicWalkingEnemy' does not implement interface member 'IAgro.agroState'. 'BasicWalkingEnemy.agroState' cannot implement 'IAgro.agroState' because it does not have the matching return type of 'AgroState'. [Assembly-CSharp]csharp(CS0738)
For now one solution I found is doing it like:
public class BasicWalkingEnemy : Entity, IAgro
{
public AgroState agroState { get { return _agroState; } }
public E1_AgroState _agroState { get; private set; }
}
But I think that is very inelegant. Is there a better solution to my problem?