What's wrong with my configuration code?

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
I'm not a fan of the new .NET 2.0 Configuration model, I find it's too long-winded and takes away the simplicity of .NET 1.x's ISectionHandler approach.

...that, plus the reflection makes me shudder.

Anyway, here's my app.config:
















And here's my Configuration code

public sealed class ManageThisSection : ConfigurationSection {

public ManageThisSection() {

}

[ConfigurationProperty("competitions")]
[ConfigurationCollection(typeof(ConfigurationElementCollection))]
public CompetitionsElement Competitions {
get { return (CompetitionsElement)base["competitions"]; }
}

public sealed class CompetitionsElement : ConfigurationElement {

private CompetitionElementCollection _competitions;

public CompetitionsElement() {
_competitions = new CompetitionElementCollection();
}

[ConfigurationProperty("", IsDefaultCollection=true)]
public CompetitionElementCollection Competitions {
get { return _competitions; }
}

public CompetitionElement GetCompetitionInfo(Int32 id) {
foreach(CompetitionElement ele in _competitions) {
if(ele.Id == id) return ele;
}
return null;
}

}

public sealed class CompetitionElementCollection : ConfigurationElementCollection {

public override ConfigurationElementCollectionType CollectionType {
get {
return ConfigurationElementCollectionType.AddRemoveClearMap;
}
}

protected override ConfigurationElement CreateNewElement() {
return new CompetitionElement();
}

protected override Object GetElementKey(ConfigurationElement element) {
return (element as CompetitionElement).Id;
}

public CompetitionElement this[Int32 index] {
get { return (CompetitionElement)BaseGet(index); }
set {
if( BaseGet(index) != null ) {
BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}

public void Add(CompetitionElement element) {
base.BaseAdd( element );
}

public void Clear() {
base.BaseClear();
}

public void Remove(CompetitionElement element) {
base.BaseRemove(element.Id);
}

public void Remove(Int32 id) {
base.BaseRemove(id);
}

public void RemoveAt(Int32 index) {
base.BaseRemoveAt(index);
}
}

public sealed class CompetitionElement : ConfigurationElement {

[ConfigurationProperty("id",IsKey=true,IsRequired=true)]
public Int32 Id {
get { return (Int32)base["id"]; }
set { base["id"] = value; }
}

[ConfigurationProperty("name",IsRequired=true)]
public String Name {
get { return (String)base["name"]; }
set { base["name"] = value; }
}

[ConfigurationProperty("path",IsRequired=true)]
public String Path {
get { return (String)base["path"]; }
set { base["path"] = value; }
}

}

}
...why isn't it working?


More...

View All Our Microsoft Related Feeds
 
Back
Top