企業庫Configuration Application Block 使用

來源:互聯網
上載者:User
   建立 工程, 用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中讀取和寫入.....

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.