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读取resource文件/路径的几种方式
    log4j:WARN Please initialize the log4j system properly解决办法
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    log4j.properties配置详解与实例-全部测试通过[转]
    testNG中dataprovider使用的两种方式
    远程仓库获取最新代码合并到本地分支
    git 冲突解决办法
    【转】JsonPath教程
    selenium及webdriver的原理【转】
    [转]Redis 数据结构简介
  • 原文地址:https://www.cnblogs.com/gwazy/p/201191.html
Copyright © 2011-2022 走看看