zoukankan      html  css  js  c++  java
  • 企业库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 
            
    {
                
    getreturn 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中读取和写入.....


      
  • 相关阅读:
    php 对输入信息的过滤代码
    svn命令备忘
    php下载文件的代码示例
    html中meta的用法
    程序员技术练级攻略
    JavaScript输出对象的内部结构
    转载Web架构师成长之路
    php代码执行效率测试工具xhprof安装&使用
    [译]Pro ASP.NET MVC 3 Framework 3rd Edition (Chapter 20 JQuery) 5.Using jQuery Events 使用jQuery事件
    [译]Pro ASP.NET MVC 3 Framework 3rd Edition (Chapter 20 JQuery) 6.Using jQuery Visual Effects 使用jQuery特效
  • 原文地址:https://www.cnblogs.com/gwazy/p/201191.html
Copyright © 2011-2022 走看看