tijian_jichuang/Code/SOH.Kernel/Configuration/MyAssemblySection.cs
2025-02-20 11:54:48 +08:00

120 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
namespace SOH.Configuration
{
public class MyAssemblySection : ConfigurationSection
{
public const string EventSection = "MyAssemblyElementsConfiguration";
private const string EventConfigElementsKey = "MyAssemblyElements";
[ConfigurationProperty(EventConfigElementsKey, IsDefaultCollection = true, IsRequired = true)]
public MyAssemblyElements MyAssemblyElements
{
get
{
return (MyAssemblyElements)this[EventConfigElementsKey];
}
set
{
base[EventConfigElementsKey] = value;
}
}
}
public class MyAssemblyElements : ConfigurationElementCollection
{
public void Add(MyAssemblyElement element)
{
base.BaseAdd(element);
}
public MyAssemblyElement this[int index]
{
get
{
return base.BaseGet(index) as MyAssemblyElement;
}
set
{
if (base.BaseGet(index) != null)
{
base.BaseRemoveAt(index);
}
this.BaseAdd(index, value);
}
}
protected override ConfigurationElement CreateNewElement()
{
return new MyAssemblyElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((MyAssemblyElement)element).ElementInformation;
}
}
public class MyAssemblyElement : ConfigurationElement
{
private const string nameName = "name";
private const string typeName = "type";
private const string assemblyName = "assembly";
[ConfigurationProperty(MyAssemblyElement.nameName, IsRequired = true)]
public string name
{
get
{
return (string)this[nameName];
}
set
{
base[nameName] = value;
}
}
[ConfigurationProperty(MyAssemblyElement.typeName, IsRequired = true)]
public string type
{
get
{
return (string)this[typeName];
}
set
{
base[typeName] = value;
}
}
[ConfigurationProperty(MyAssemblyElement.assemblyName, IsRequired = true)]
public string assembly
{
get
{
return (string)this[assemblyName];
}
set
{
base[assemblyName] = value;
}
}
}
}