Files
mono/mcs/class/System.Configuration/Test/standalone/t41.cs
T
Atsushi Eno 3ec6ab7336 2006-12-27 Atsushi Enomoto <[email protected]>
* 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
2006-12-27 05:59:54 +00:00

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);
}
}