I have an interface with properties:
public interface IEntityModifier
{
...
bool AutoDetachOnFinished { get; set; }
bool Finished { get; }
...
}
Then I implement it:
bool IEntityModifier.AutoDetachOnFinished { get; set; }
bool IEntityModifier.Finished { get { return this.mFinished; } }
But when I need to access AutoDetachOnFinished
within the same class, a compiler error pops out:
void IEntityModifier.Update(IEntity pEntity, Microsoft.Xna.Framework.GameTime pGameTime)
{
if (!this.mFinished)
{
this.Value += this.Delta * (float)pGameTime.ElapsedGameTime.TotalSeconds;
if (this.Value >= this.Max)
{
this.Value = this.Max;
this.mFinished = true;
if (this.AutoDetachOnFinished) { /* Error Here */ }
}
}
}
The error message:
14 'MEngine.Entities.EntityModifier.SingleValueEntityModifier' does not contain a definition for 'AutoDetachOnFinished' and no extension method 'AutoDetachOnFinished' accepting a first argument of type 'MEngine.Entities.EntityModifier.SingleValueEntityModifier' could be found (are you missing a using directive or an assembly reference?)
I have 2 questions:
IEntityModifier.
s (so IEntityModifier.Update
would become Update
, apply to any implemented method)?AutoDetachOnFinished
?You have implemented these as explicit interface implementations, meaning you can only access them through a variable of the interface type - IEntityModifier
.
Either do that:
if (((IEntityModifier)this).AutoDetachOnFinished)
or remove the interface name from the implementation:
bool AutoDetachOnFinished { get; set; }
bool Finished { get { return this.mFinished; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With