不能在XML序列化中隐式转换类型系统泛型列表
本文关键字:转换 类型系统 泛型 列表 XML 序列化 不能 | 更新日期: 2023-09-27 18:14:24
我有一个asp.net应用程序背后的c#代码。试图使用类序列化为xml。但是得到错误:
cannot implicitly convert Cannot convert type system.collection.generic.list
本行出现在:
CourtDocumentEvent = new List<DocumentEventCourtDocumentEvent>
.CS文件代码:
AddOdyDocToWorkflowRequest AddOdyDocToWorkflowRequest = new AddOdyDocToWorkflowRequest()
{
CaseDocument = new List<CaseDocument>()
{
new CaseDocument()
{
CaseAugmentation = new List<CaseAugmentation>(){
new CaseAugmentation(){
DocumentEvent = new List<DocumentEvent>()
{
new DocumentEvent()
{
CourtDocumentEvent = new List<DocumentEventCourtDocumentEvent>()
{
new DocumentEventCourtDocumentEvent()
{
DocumentData = CaseNumberTextBox.Text+ "," + DocumentCode
}
}
}
}
}
}
}
}
};
这段代码将把你的对象转换成XML
public static string ConvertToXml(object obj)
{
StringWriter result = new StringWriter(new StringBuilder());
try
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
serializer.Serialize(result, obj);
return result.ToString();
}
catch (Exception ex)
{
return result.ToString();
}
}