企业库Configuration Application Block 使用
新建 工程, 用Enterprise Library Configuration打开 web.config
新建 configsection .
重命名为 Edit ,
然后在edit 结点新建
XML File Storage Provider
Xml Serializer Transformer
设置 XML File Storage Provider 它的filename 为存取信息的 config文件
(你要先在项目中新建一个config 文件,在试例中命名为 Setting.config)
然后保存

using System;
using System.Text;
using System.Xml.Serialization;


namespace Intlib


{

/**//// <summary>
/// Persen 的摘要说明。
/// </summary>
public class Persen

{
private string name ;
private int age;
private string country;

public Persen()

{
//
// TODO: 在此处添加构造函数逻辑
//
}

public string Name

{

get
{ return name; }

set
{ name = value; }
}

public int Age

{

get
{return age ;}

set
{age=value ;}
}
public string Country

{

get
{return country ;}

set
{country=value ;}

}

}
}
一个为写入,一个为读取,


private void Button1_Click(object sender, System.EventArgs e)

{
Persen ps=new Persen ();
ps.Name=this.TextBox1 .Text ;
ps.Age =int.Parse (this.TextBox2.Text) ;
ps.Country =this.TextBox3.Text ;
ConfigurationManager.WriteConfiguration ("Edit",ps);

}

private void Button2_Click(object sender, System.EventArgs e)

{
Persen ps = ConfigurationManager.GetConfiguration("Edit") as Persen ;
this.TextBox1 .Text =ps.Name;
this.TextBox2.Text =ps.Age.ToString ();
this.TextBox3.Text =ps.Country ;

}
企业库会对对象自动进行序列化,和反序列化...
方便从 config中读取和写入.....
新建 configsection .
重命名为 Edit ,
然后在edit 结点新建
XML File Storage Provider
Xml Serializer Transformer
设置 XML File Storage Provider 它的filename 为存取信息的 config文件
(你要先在项目中新建一个config 文件,在试例中命名为 Setting.config)
然后保存

using System;
using System.Text;
using System.Xml.Serialization;

namespace Intlib

{
/**//// <summary>
/// Persen 的摘要说明。
/// </summary>
public class Persen
{
private string name ;
private int age;
private string country;
public Persen()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string Name 
{
get
{ return name; }
set
{ name = value; }
} 
public int Age
{
get
{return age ;}
set
{age=value ;}
}
public string Country
{
get
{return country ;}
set
{country=value ;}
}
}
}
一个为写入,一个为读取,


private void Button1_Click(object sender, System.EventArgs e)
{
Persen ps=new Persen ();
ps.Name=this.TextBox1 .Text ;
ps.Age =int.Parse (this.TextBox2.Text) ;
ps.Country =this.TextBox3.Text ;
ConfigurationManager.WriteConfiguration ("Edit",ps);
}
private void Button2_Click(object sender, System.EventArgs e)
{
Persen ps = ConfigurationManager.GetConfiguration("Edit") as Persen ;
this.TextBox1 .Text =ps.Name;
this.TextBox2.Text =ps.Age.ToString ();
this.TextBox3.Text =ps.Country ;
}企业库会对对象自动进行序列化,和反序列化...
方便从 config中读取和写入.....