Я пробовал абстрактный, который не может быть сериализован, Я пытался сделать класс XMLDocument универсальным, но это тоже не помогло.
Как мне реализовать универсальный/абстрактный/интерфейс, чтобы это работало?
Код: Выделить всё
public class Slide where DocumentType : XMLDocument
{
[DataMember]
public DocumentType Page{ get; set; }
//more code down here...
}
Код: Выделить всё
List slides = new Slide(RSSDocument); Главное окно
Код: Выделить всё
static RSSDocument RSSDocument = new RSSDocument();
Slide slide = new Slide();
List slides = new List();
public MainWindow()
{
InitializeComponent();
slides.AddRange(slide.ReadSerializedSlides());
SetTimers();
slides.Clear();
slides.AddRange(MediaRefresh(slide.ReadSerializedSlides()));
}
Код: Выделить всё
[DataContract]
[XmlInclude(typeof(RSSDocument))]
[XmlInclude(typeof(WeatherData))]
[XmlInclude(typeof(GatherConfig))]
public class XMLDocument
{
public void SerializeDocument()
{
string filename = @"\\motnas\mofilesvr\isystems\apps - IT and utilities\ Programs\DisplayBoardsConfigs\" +
this.GetType().ToString().Replace("DisplayBoard.Classes.", "") + ".txt";
FileStream fs = new FileStream(filename, FileMode.Create);
DataContractSerializer serializer = new DataContractSerializer(this.GetType());
serializer.WriteObject(fs, this);
fs.Close();
}
public object DeserializeDocument()
{
string filename = @"\\motnas\mofilesvr\isystems\apps - IT and utilities\ Programs\DisplayBoardsConfigs\" +
this.GetType().ToString().Replace("DisplayBoard.Classes.", "") + ".txt";
DataContractSerializer serializer = new DataContractSerializer(this.GetType());
XmlSerializer xmlSerializer = new XmlSerializer(this.GetType());
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
XmlDictionaryReader reader =
XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
var XMLDoc = serializer.ReadObject(reader);
fs.Close();
return XMLDoc;
}
public virtual Page CreatePage()
{
return new Page();
}
}
Код: Выделить всё
[DataContract]
public class RSSDocument : XMLDocument
{
[DataMember]
public string Title { get; set; }
[DataMember]
public string Image { get; set; }
[DataMember]
public string Body { get; set; }
[DataMember]
public string TimeStamp { get; set; }
//Other Functions
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... ialization
Мобильная версия