Similiar to this question: How can I require a method argument to implement multiple interfaces? I want a method argument to implement several interfaces.
The interfaces shall be combinable in arbitrary fashion and I don't want to create an interface for each valid combination.
Think of a file. It can be:
- readable =>
IReadable - writeable =>
IWriteable - an archive =>
IArchive - automatically generated =>
IGenerated
...
If I want to express that an argument needs to be an writable, generated archive I don't want to generate IWritableGeneratedArchive since there are too combinations and I want to use it with some existing classes I cannot modify.
Pseudocode:
void WriteTo( IWritable + IGenerated + IArchive file)
{
//...
}
The solution I found here: How can I require a method argument to implement multiple interfaces? adjusted for C#.
Credits go to Michael Myers