Jump to content

Recommended Posts

Posted

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

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...