zoukankan      html  css  js  c++  java
  • 自定义配置节注意事项

    1、属性大小写问题

    比如有这样一个配置节,其中有三个属性name,ip,port
      <Server name="server1" ip="192.168.0.11" port="80" />

    那么对应的类要跟这个名字完全匹配,包括大小写。

    public class Server : ConfigurationElement
    {
        [ConfigurationProperty("name", DefaultValue = "Server1", IsRequired = true, IsKey = true)]
        public string Name {get;set;}
       

        [ConfigurationProperty("ip", DefaultValue = "127.0.0.1", IsRequired = true, IsKey = false)]
        public string IP {get;set;}

        [ConfigurationProperty("port", DefaultValue = "80", IsRequired = true, IsKey = false)]
        public int Port {get;set;}

    }


     

    2、配置节名称(也是一个大小写问题)

    这样一个配置节

    <ServerList>
      <server name="server1" ip="192.168.0.11" port="80" />
      <server name="server2" ip="192.168.0.12" port="80" />
    </ServerList>

    public class ServerCollection : ConfigurationElementCollection
    {

        … …

        protected override string ElementName
        {
            get { return "server"; }
        }

    }

    3、section的名称要对应

    <configSections>
      <section name="serverList" type="Aricc.Engine.Client.Config.ServerList,Aricc.Engine.Client" />
    </configSections>
    <serverList>
      <server name="server1" ip="192.168.0.11" port="80" />
      <server name="server2" ip="192.168.0.12" port="80" />
    </serverList>

    对应后台代码

    Config.ServerList configList = (Config.ServerList)ConfigurationManager.GetSection("serverList") as Config.ServerList;

    对应的配置节类的名称可以不一样

    public class ServerList : ConfigurationSection{}

  • 相关阅读:
    软件大赛excel转换
    迷你表单美化框架 Ideal Forms
    FLV播放器代码 网页FLV在线播放代码
    网站被降权了该怎么办
    jQuery弹出层插件bPopup
    如何去增加外部链接
    IIS MIME设置
    jQuery无缝滚动
    jQuery表单验证插件 jQuery validate
    dedecms实现关键字自动加内链
  • 原文地址:https://www.cnblogs.com/Aricc/p/1660427.html
Copyright © 2011-2022 走看看