[java]代码库
public static string Serialize<BusinessObject>(List<BusinessObject> GenericList) {
XmlDocument result = new XmlDocument();
result.LoadXml("<Root></Root>");
foreach (BusinessObject obj in GenericList) {
XmlElement Item = result.CreateElement("Item");
PropertyInfo[] properties = obj.GetType().GetProperties();
foreach (PropertyInfo property in properties) {
if (property.GetValue(obj, null) != null) {
XmlElement element = result.CreateElement(property.Name);
element.SetAttribute("Type", property.PropertyType.Name);
element.InnerText = property.GetValue(obj, null).ToString();
Item.AppendChild(element);
}
}
result.DocumentElement.AppendChild(Item);
}
return result.InnerXml;
}