I have this code, the parent class has an abstract bool Filter(EntityComponent entity) but in this class, I prefer implementing bool Filter(BaseComponent entity) because others are calling the latter as well (EntityComponent is a BaseComponent). To prevent StackOverflow, I cast it to BaseComponent so the correct overload can be called:
protected override bool Filter(EntityComponent entity) => Filter((BaseComponent)entity);
protected bool Filter(BaseComponent entity)
{
return
(AllowBeavers && entity.GetComponentFast<BeaverSpec>())
|| (AllowBots && entity.GetComponentFast<BotSpec>());
}
Now I am surprised that VS asks me to remove the cast, and it even refers to the correct method when removing such cast:
Why is Filter(BaseComponent) being chosen when EntityComponent surely is more detailed? How would that not make a recursion without the cast?
