I know this does not answer your question, but since you do not have the opportunity to do what you ask, I thought I would share my own approach so that others could see.
I use a hybrid of the offers offered by Mark and Andrew.
In my application, all domain objects are obtained from an abstract base class:
public abstract class Entity {
The interface itself defines a simple accessor:
public interface IHasDescription : IEntity {
So, now the built-in return mechanism - or, in other words, Entity , which implements IHasDescription , should provide EntityDescription , but any Entity can still convert to string.
I know that this is not radically different from the other solutions proposed here, but I like the idea of ββminimizing the responsibility of the basic Entity type, so the implementation of the description interface remains optional, but you are forced to actually implement the description method if you implement the interface.
IMHO, the interfaces implemented by the base class object should not be "counted" as implemented - it would be nice to have a compiler option for it, but, well, good ...
mindplay.dk Aug 04 2018-11-18T00: 00Z
source share