Yes, the title doesn't make much sense, but here's my situation.
I have two interfaces, say IGen and ITrans. Some of my classes implement IGen, some implement ITrans and some implement both
ITrans has one method (Translate) and IGen has one method (Generate). For the classes that implement both ITrans and IGen Generate simply calls Translate.
I also have an Interface IGenAndTrans which is simply defined as
public interface IGenAndTrans : IGen , ITrans
{
}
And I have a class (call it Holder) which has IGenAndTrans as a property.
[Serializable] //<- Problem
public class Holder
{
public IGenAndTrans GeneratorAndTranslator { get; set;}
}
Now, I want to mark the class Holder with [SerializableAttribute] and use the XmlSerializer. However I can't do this because Holder has a property which is an interface. Normally the recommended approach would be to make IGenAndTrans an abstract base class and use XmlInclude. I've done this successfully in the past.
However I'm unsure of how to do that in this case. Because a lot of my classes implement both IGen and ITrans they can't simply inherit from an abstract base class. This would mean I would need to split each of those classes into two classes with the corresponding duplication of code (since Generate calls Translate a lot of the time)
Any recommendations (if I've managed to explain myself well enough)? Maybe I'm too close to the code and should be implementing it differently.