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中读取和写入.....


      
  • 相关阅读:
    Java基础之抽象类和多态
    Java基础之继承重载重写与this和super
    Java基础之StringBuffer的使用
    Java基础之String的方法与常量池
    Spring Boot之JSP开发
    Spring Boot之thymeleaf中替换th:each使用
    本周进度
    问卷调查立题报告(三人行)
    本周进度(复习软考)
    软件需求十步走之阅读笔记02
  • 原文地址:https://www.cnblogs.com/gwazy/p/201191.html
Copyright © 2011-2022 走看看