I have a custom configuration setup.
public class GalleryResizeOptionsElement : ConfigurationElement
{
[ConfigurationProperty("name")]
public string Name
{
get { return (string)this["name"]; }
}
[ConfigurationProperty("width")]
public int Width
{
get { return (int)this["width"]; }
}
[ConfigurationProperty("height")]
public int Height
{
get { return (int)this["height"]; }
}
}
public class GalleryResizeOptionsCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new GalleryResizeOptionsElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((GalleryResizeOptionsElement)element).Name;
}
public override ConfigurationElementCollectionType CollectionType
{
get { return ConfigurationElementCollectionType.BasicMap; }
}
/// <summary>
/// The element name of the configuration elements in the config file,
/// as set at UserCommandConfigurationConstants.ElementName
/// </summary>
protected override string ElementName
{
get { return "add"; }
}
/// <summary>
/// This is a convenience added to allow selection from the collection
/// via the commandkey as an index
/// </summary>
/// <returns></returns>
public GalleryResizeOptionsElement this[string name]
{
get { return (GalleryResizeOptionsElement)this.BaseGet(name); }
}
}
public class GalleryConfigurationSection : ConfigurationSection
{
public virtual GalleryResizeOptionsCollection ResizeOptions
{
get { return (GalleryResizeOptionsCollection) base["resizeOptions"]; }
}
}
Add in the web.config file there is a section that contains this xml config.
<resizeOptions>
<add name="Square" width="100" height="100" />
<add name="Rectangle" width="200" height="100" />
<add name="Hero" width="600" height="400" />
</resizeOptions>
I've left a lot of the other code out for brevity, but I think I've included everything that is required to ask my question.
How do I alter GalleryResizeOptionsCollection so that I can return a list of all the GalleryResizeOptionsElements? Or in clearer terms, I want to be able to return a list of all the "add" elements.