XMLSerializer
初始化并传递一个实例Appointment
(来自 EWS API)时,我遇到了一个异常:
Microsoft.Exchange.WebServices.Data.Appointment 无法序列化,因为它没有无参数构造函数。
这是我的代码:
private static string FindAppointmentsAsXmlString(CalendarView calendar, ExchangeService serv)
{
FindItemsResults<Appointment> appointments = serv.FindAppointments(
WellKnownFolderName.Calendar, calendar);
List<Appointment> appointmentsList = appointments.ToList();
var serializer = new XmlSerializer(appointmentsList.GetType());
var writer = new StringWriter();
try
{
serializer.Serialize(writer, appointmentsList);
Console.WriteLine(writer.GetStringBuilder().ToString());
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
}
return writer.GetStringBuilder().ToString();
}