I have an interface IStorageManager
that allows me to store data, different implementations are for json-file-based storage, xml-file-based, etc
I have the interface IStorable
and I want to force all classes implementing IStorable
to have the [Serializable] header. So in the IStorageManager
I can implement it like this :
public interface IStorageManager
{
IStorable Load<IStorable>(string Path);
void Save<IStorable>(IStorable objToSave, string path);
}
public class XMLStorageManager : IStorageManager
{
public void Save<T>(T objToSave, string path)
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
using (TextWriter writer = new System.IO.StreamWriter(System.IO.Path.GetFullPath(path)))
{
serializer.Serialize(writer, typeof(T));
}
}
}
Is there a way to specify that in the interface ??