zoukankan      html  css  js  c++  java
  • Framework2.0中自定义配置节点注意事项

    最近在开发自己架构的过程中,在一个配置自定义节点的模块遇到了麻烦。错误代码如下

    代码片段

    ...

    代码
      [ConfigurationProperty("mode", DefaultValue = 0)]
            
    public SecureWebPageMode Mode
            {
                
    get
                {
                    
    return (SecureWebPageMode)this["mode"] ;
                }
                
    set
                {
                    
    this["mode"]=value;
                }
            }

    ...

    正确代码如下:

    代码片段

    ...

    代码
     [ConfigurationProperty("mode", DefaultValue = SecureWebPageMode.On)]
            
    public SecureWebPageMode Mode
            {
                
    get
                {
                    
    return (SecureWebPageMode)this["mode"] ;
                }
                
    set
                {
                    
    this["mode"]=value;
                }
            }

    ...

    在ConfigurationProperty特性中设置DefaultValue,枚举值是不能用Int替代的,我认为自定义配置节点微软在类型强转方面有不完美的地方。

    作者:Olar Tan
    出处:http://www.cnblogs.com/olartan
    ♪:没有做不到的 只有偷懒而错过的 ♪

  • 相关阅读:
    System.Collections.Generic.IEnumerable.cs
    System.Collections.IList.cs
    茶-保健茶:松针茶
    中药-中药名:松针
    植物:松树
    LDAP-常用命令
    dsadm-dsconf数据导入导出
    SUN-LDAP6.3_RHEL 5.0-卸载LDAP
    passwd-shadow文件
    文件及目录的权限
  • 原文地址:https://www.cnblogs.com/olartan/p/1622959.html
Copyright © 2011-2022 走看看