我需要将 IEnumerable 对象转换为 XML 字符串
IEnumerable<KeyValuePair<string, object>> myObject
我尝试使用下面的代码,但这不起作用
ConvertToXmlString(myObject);
public static string ConvertToXmlString(object name)
{
try
{
var stringwriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(name.GetType());
serializer.Serialize(stringwriter, name);
return stringwriter.ToString();
}
catch
{
return "cannot be converted to XML";
}
}
有什么建议么 ?