I have Class Calendar
public class Calendar
{
public static List<ServiceCalendar> DaysOfWeek
{
get
{
return new List<Calendar>
{
new Calendar { Id = 1, Code = "Mo", Name = "Mo" },
new Calendar { Id = 2, Code = "Tu", Name = "Tu" },
new Calendar { Id = 3, Code = "We", Name = "We" },
new Calendar { Id = 4, Code = "Th", Name = "Th" },
new Calendar { Id = 5, Code = "Fr", Name = "Fr" },
new Calendar { Id = 6, Code = "Sa", Name = "Sa" },
new Calendar { Id = 7, Code = "Su", Name = "Su" }
};
}
}
public static List<Calendar> MonthsOfYear
{
get
{
return new List<Calendar>
{
new Calendar { Id = 1, Code = "Jan", Name = "Jan" },
new Calendar { Id = 2, Code = "Feb", Name = "Feb" },
new Calendar { Id = 3, Code = "Mar", Name = "Mar" },
new Calendar { Id = 4, Code = "Apr", Name = "Apr" },
new Calendar { Id = 5, Code = "May", Name = "May" },
new Calendar { Id = 6, Code = "Jun", Name = "Jun" },
new Calendar { Id = 7, Code = "Jul", Name = "Jul" },
new Calendar { Id = 8, Code = "Aug", Name = "Aug" },
new Calendar { Id = 9, Code = "Sep", Name = "Sep" },
new Calendar { Id = 10, Code = "Oct", Name = "Oct" },
new Calendar { Id = 11, Code = "Nov", Name = "Nov" },
new Calendar { Id = 12, Code = "Dec", Name = "Dec" },
};
}
}
}
My Serizlization Class
public static class SerializationUtil
{
public static T Deserialize<T>(XDocument doc)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (var reader = doc.Root.CreateReader())
{
return (T)xmlSerializer.Deserialize(reader);
}
}
public static XDocument Serialize(this object obj)
{
XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
XDocument doc = new XDocument();
using (var writer = doc.CreateWriter())
{
xmlSerializer.Serialize(writer, obj);
}
return doc;
}
我需要序列化两个对象 MonthsOfYear 和 DaysOfWeek 并将它们添加到 XDocument
XDocument doc = new XDocument();
doc = SerializationUtil.Serialize(trigger.MonthsOfYear);
var daysOfWeek = SerializationUtil.Serialize(trigger.DaysOfWeek)
如何将 DaysOfWeek 序列化添加到 doc 和反序列化之后