here's an interface I use.
public interface IPresentism {
public abstract bool isPresent { get; }
public virtual bool isAbsent => !isPresent;
}
isPresent is abstract so the interface user has to implement it.
Interface also carries a handy negation of that, isAbsent, which is implemented, and virtual so it should be added to all subclasses it's mixed in with (actually it's never overridden but whatever, remove 'overide' from isAbsent doesn't change anything). Try using IPresentism then..
public class tester : IPresentism {
public bool isPresent => true;
public bool checkAbsentVisible =>
this.isAbsent; // fails
}
Error is
Error CS1061 'tester' does not contain a definition for 'isAbsent' and no accessible extension method 'isAbsent' accepting a first argument of type 'tester' could be found.
C#8 is supposed to support these "You can now add members to interfaces and provide an implementation for those members" https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#default-interface-methods. Perhaps it really is methods not properties, try that:
public interface IPresentism {
public abstract bool isPresent(); // { get; }
public virtual bool isAbsent() => !isPresent();
}
public class tester : IPresentism {
public bool isPresent() => true;
public bool checkAbsentVisible =>
this.isAbsent(); // nope again
}
Same error. What am I misunderstanding?