111,094
社区成员




using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace Com
{
[Serializable]
public class ReportChart
{
private List<String> categoryGroupingList = new List<String>();
[XmlArray("CategoryGroupings")]
[XmlArrayItem("CategoryGrouping")]
public List<String> CategoryGroupingList
{
get { return categoryGroupingList; }
set { categoryGroupingList = value; }
}
}
}
[XmlIgnore]
public List<String> CategoryGroupingList
{
get { return categoryGroupingList; }
set { categoryGroupingList = value; }
}
[XmlArray("CategoryGroupings")]
[XmlArrayItem("CategoryGrouping")]
public List<String> CategoryGroupingListSerial
{
get
{
if (categoryGroupingList.Count == 0)
{
return null;
}
return categoryGroupingList;
}
set {
categoryGroupingList = value;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
namespace Com
{
public static class XmlUtil
{
public static object Deserialize(string xml, Type type)
{
XmlSerializer xs = new XmlSerializer(type);
StringReader sr = new StringReader(xml);
object obj = xs.Deserialize(sr);
return obj;
}
public static void SaveXml(string filePath, object obj)
{
SaveXml(filePath, obj, null);
}
public static void SaveXml(string filePath, object obj, XmlSerializerNamespaces nameSpace)
{
if (obj == null)
{
return;
}
Type type = obj.GetType();
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filePath, false, Encoding.UTF8))
{
try
{
XmlSerializer xs = new XmlSerializer(type);
if (nameSpace != null)
{
xs.Serialize(writer, obj, nameSpace);
}
else
{
xs.Serialize(writer, obj);
}
}
catch (Exception ex)
{
Console.WriteLine("exception :" + ex + " is null: " + (ex == null));
}
writer.Close();
}
}
public static object LoadXml(string filePath, System.Type type)
{
if (!System.IO.File.Exists(filePath))
return null;
using (System.IO.StreamReader reader = new System.IO.StreamReader(filePath))
{
XmlSerializer xs = new XmlSerializer(type);
try
{
object obj = xs.Deserialize(reader);
reader.Close();
return obj;
}
catch (Exception e)
{
}
return null;
}
}
}
}
namespace Com
{
[Serializable]
public class ReportChart
{
private List<String> categoryGroupingList;
[XmlIgnore]
public List<String> CategoryGroupingList
{
get { return categoryGroupingList; }
set { categoryGroupingList = value; }
}
[XmlArray("CategoryGroupings")]
[XmlArrayItem("CategoryGrouping")]
public String[] CategoryGroupingListSerial
{
get
{
if (categoryGroupingList == null || categoryGroupingList.Count == 0)
{
return null;
}
return categoryGroupingList.ToArray();
}
set {
if (value == null)
{
categoryGroupingList = null;
}
else
{
categoryGroupingList = new List<string>();
categoryGroupingList.AddRange(value);
}
}
}
}
}
namespace Com
{
[Serializable]
public class ReportChart
{
//此处不能初始化:categoryGroupingList = new List<String>();
private List<String> categoryGroupingList;
[XmlIgnore]
public List<String> CategoryGroupingList
{
get { return categoryGroupingList; }
set { categoryGroupingList = value; }
}
[XmlArray("CategoryGroupings")]
[XmlArrayItem("CategoryGrouping")]
public List<String> CategoryGroupingListSerial
{
//Load(Deserialize): categoryGroupingList == null
//Save(Serialize): categoryGroupingList == null || categoryGroupingList.Count == 0
get
{
if (categoryGroupingList == null || categoryGroupingList.Count == 0)
{
return null;
}
return categoryGroupingList;
}
//set {categoryGroupingList = value;}
}
}
}