mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 17:02:10 -10:00
* ConfigurationElementCollection.cs : fixed BaseAdd() with throwIfExists to not raise an error for identical element but for different element which shares the same key. Fix by Konstantin Triger. * t38.cs, t38.exe.config, t38.exe.expected : new test for duplicate element. * t39.cs, t39.exe.config, t39.exe.expected : new test for identical element. * t40.* : similar test to t38 but with Alternate collection. * t41.* : similar test to t39 but with Alternate collection. * Makefile : added above. svn path=/trunk/mcs/; revision=70107
61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
using System;
|
|
using System.Configuration;
|
|
|
|
public class MyElement : ConfigurationElement
|
|
{
|
|
public MyElement ()
|
|
{
|
|
}
|
|
|
|
[ConfigurationProperty ("name", Options = ConfigurationPropertyOptions.IsKey)]
|
|
public string Name {
|
|
get { return (string) this ["name"]; }
|
|
}
|
|
[ConfigurationProperty ("value")]
|
|
public string Value {
|
|
get { return (string) this ["value"]; }
|
|
}
|
|
}
|
|
|
|
[ConfigurationCollection (typeof (MyElement), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMapAlternate)]
|
|
public class MyElementCollection : ConfigurationElementCollection
|
|
{
|
|
protected override ConfigurationElement CreateNewElement ()
|
|
{
|
|
return new MyElement ();
|
|
}
|
|
protected override object GetElementKey (ConfigurationElement e)
|
|
{
|
|
return ((MyElement) e).Name;
|
|
}
|
|
|
|
public void Add (MyElement e)
|
|
{
|
|
BaseAdd (e);
|
|
}
|
|
|
|
protected override void BaseAdd (ConfigurationElement e)
|
|
{
|
|
base.BaseAdd (e);
|
|
}
|
|
}
|
|
|
|
public class MySection : ConfigurationSection
|
|
{
|
|
[ConfigurationProperty ("MyElements")]
|
|
public MyElementCollection MyElements {
|
|
get { return (MyElementCollection) this ["MyElements"]; }
|
|
}
|
|
}
|
|
|
|
public class Driver
|
|
{
|
|
public static void Main ()
|
|
{
|
|
MySection ms = (MySection) ConfigurationManager.GetSection ("MySection");
|
|
foreach (MyElement e in ms.MyElements)
|
|
Console.WriteLine (e.Name);
|
|
}
|
|
}
|
|
|