Unexpected RegexStringValidator failure in ConfigurationProperty in custom ConfigurationElement

前端 未结 2 1891
生来不讨喜
生来不讨喜 2020-12-19 06:09

I am writing my own custom configuration section and have a ConfigurationProperty defined in a ConfigurationElement like so:

[ConfigurationProperty(\"startTi         


        
相关标签:
2条回答
  • 2020-12-19 06:43

    I wonder if the indirection from the property requires a double-escaping of the contents. If yes, then instead of:

    "\\d{2}:\\d{2}:\\d{2}"
    

    use:

    @"\\d{2}:\\d{2}:\\d{2}"
    

    Ordinarly I would think that is too much, but give it a try.

    0 讨论(0)
  • 2020-12-19 06:50

    Try to define the default value that will pass the validation:

    [ConfigurationProperty("startTime", IsRequired = false, DefaultValue = "00:00:00")]
    [RegexStringValidator(@"\d{2}:\d{2}:\d{2}")]
    public string StartTime
    {
        get 
        {
            return (string) this["startTime"];
        }
    
        set
        {
            this["startTime"] = value;
        }
    }
    
    0 讨论(0)
提交回复
热议问题