How to include simple collections in ConfigurationSection

前端 未结 4 585
不思量自难忘°
不思量自难忘° 2020-12-20 11:49

Is there a way for me to include a simple array of strings, or List on my custom subclass of ConfigurationSection? (Or an array or generic list of simple data

4条回答
  •  北海茫月
    2020-12-20 12:28

    I know that the question has been answered long time ago... but in my 'ConfigurationElement' classes, for string collection, I usually do the following:

    [ConfigurationProperty("myStringCollectionProperty", DefaultValue = "")]
    [TypeConverter(typeof(CommaDelimitedStringCollectionConverter))]
    public StringCollection MyStringCollectionProperty
    {
        get { return (StringCollection)this["myStringCollectionProperty"]; }
        set { this["myStringCollectionProperty"] = value; }
     }
    

    And you can get a string list from this property with

    List myStrings = config.MyStringCollectionProperty.Cast.ToList()
    

提交回复
热议问题