易截截图软件、单文件、免安装、纯绿色、仅160KB

C#序列化与反序列化Xml,利用范型做通用化处理

public class yzzSerialize
{
private yzzSerialize()
{ }
private static yzzCache cache = new yzzCache();
public static T GetfromXml<T>(string xmlpath, T t)
{
using (FileStream fs = new FileStream(xmlpath, FileMode.Open, FileAccess.Read))
{
Type type = typeof(T);
XmlSerializer xs = cache[type.FullName] as XmlSerializer;
if (xs == null)
{
xs = new XmlSerializer(type);
cache[type.FullName] = xs;
}
t = (T)xs.Deserialize(fs);
fs.Close();
return t;
}
}
public static void SetToXml<T>(string xmlpath, T t)
{
if (t == null)
return;
using (FileStream fs = new FileStream(xmlpath, FileMode.Create, FileAccess.Write))
{
Type type = typeof(T);
XmlSerializer xs = cache[type.FullName] as XmlSerializer;
if (xs == null)
{
xs = new XmlSerializer(type);
cache[type.FullName] = xs;
}
xs.Serialize(fs, t);
t = default(T);
fs.Close();
}
}
}


相关文档:

xml转换为dataset

        /// <summary>
        /// 读取数据集并加入缓存
        /// sea 2009-12-11
        /// </summary>
      &nb ......

c# 从XML读数据

C#
 DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/Config/User_yhlx_Jb.xml"));
DataView dv = ds.Tables[0].DefaultView;
//dv.RowFilter = "State=0";
this.DropDownList1.DataSource = dv;
this.DropDownList1.DataTextField = "text";
this ......

xml操作

     protected void Button1_Click(object sender, EventArgs e)
        {
            //为response(star)节点 和  Cabins(f) cabin节点分别添加个
      &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号