|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml;
namespace DynamicDecoratorAOP.Configuration
{
public class AspectObjectConfigElement : ConfigurationElement
{
public AspectObjectConfigElement(String newName, String newType, String newInterface, String newMethods, String newPreDecoration, String newPostDecoration)
{
Name = newName;
TargetType = newType;
Interface = newInterface;
Methods = newMethods;
PreDecoration = newPreDecoration;
PostDecoration = newPostDecoration;
}
public AspectObjectConfigElement() {}
public AspectObjectConfigElement(String elementName)
{
Name = elementName;
}
[ConfigurationProperty("name", DefaultValue = "0", IsRequired = true, IsKey = true)]
public string Name
{
get
{
return (string)this["name"];
}
set
{
this["name"] = value;
}
}
[ConfigurationProperty("type", DefaultValue = "object", IsRequired = true, IsKey = false)]
public string TargetType
{
get
{
return (string)this["type"];
}
set
{
this["type"] = value;
}
}
[ConfigurationProperty("interface", DefaultValue = "object", IsRequired = true, IsKey = false)]
public string Interface
{
get
{
return (string)this["interface"];
}
set
{
this["interface"] = value;
}
}
[ConfigurationProperty("methods", DefaultValue = null, IsRequired = false)]
public string Methods
{
get
{
return (string)this["methods"];
}
set
{
this["methods"] = value;
}
}
[ConfigurationProperty("predecoration", DefaultValue = null, IsRequired = false)]
public string PreDecoration
{
get
{
return (string)this["predecoration"];
}
set
{
this["predecoration"] = value;
}
}
[ConfigurationProperty("postdecoration", DefaultValue = null, IsRequired = false)]
public string PostDecoration
{
get
{
return (string)this["postdecoration"];
}
set
{
this["postdecoration"] = value;
}
}
protected override void DeserializeElement(System.Xml.XmlReader reader, bool serializeCollectionKey)
{
base.DeserializeElement(reader, serializeCollectionKey);
// You can your custom processing code here.
}
protected override bool SerializeElement(System.Xml.XmlWriter writer, bool serializeCollectionKey)
{
bool ret = base.SerializeElement(writer, serializeCollectionKey);
// You can enter your custom processing code here.
return ret;
}
protected override bool IsModified()
{
bool ret = base.IsModified();
// You can enter your custom processing code here.
return ret;
}
}
public class AspectObjectsCollection : ConfigurationElementCollection
{
public AspectObjectsCollection()
{
}
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.AddRemoveClearMap;
}
}
protected override ConfigurationElement CreateNewElement()
{
return new AspectObjectConfigElement();
}
protected override ConfigurationElement CreateNewElement(string elementName)
{
return new AspectObjectConfigElement(elementName);
}
protected override Object GetElementKey(ConfigurationElement element)
{
return ((AspectObjectConfigElement)element).Name;
}
public new string AddElementName
{
get { return base.AddElementName; }
set { base.AddElementName = value; }
}
public new string ClearElementName
{
get { return base.ClearElementName; }
set { base.ClearElementName = value; }
}
public new string RemoveElementName
{
get { return base.RemoveElementName; }
}
public new int Count
{
get { return base.Count; }
}
public AspectObjectConfigElement this[int index]
{
get
{
return (AspectObjectConfigElement)BaseGet(index);
}
set
{
if (BaseGet(index) != null)
{
BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}
new public AspectObjectConfigElement this[string Name]
{
get
{
return (AspectObjectConfigElement)BaseGet(Name);
}
}
public int IndexOf(AspectObjectConfigElement aspectObj)
{
return BaseIndexOf(aspectObj);
}
public void Add(AspectObjectConfigElement aspectObj)
{
BaseAdd(aspectObj);
// Add custom code here.
}
protected override void
BaseAdd(ConfigurationElement element)
{
BaseAdd(element, false);
// Add custom code here.
}
public void Remove(AspectObjectConfigElement aspectObj)
{
if (BaseIndexOf(aspectObj) >= 0)
BaseRemove(aspectObj.Name);
}
public void RemoveAt(int index)
{
BaseRemoveAt(index);
}
public void Remove(string name)
{
BaseRemove(name);
}
public void Clear()
{
BaseClear();
// Add custom code here.
}
}
public class DynamicDecoratorSection : ConfigurationSection
{
[ConfigurationProperty("objectTemplates", IsDefaultCollection = false)]
public AspectObjectsCollection objectTemplates
{
get
{
AspectObjectsCollection objectTemplatesCollection = (AspectObjectsCollection)base["objectTemplates"];
return objectTemplatesCollection;
}
}
//protected override void DeserializeSection(System.Xml.XmlReader reader)
//{
// base.DeserializeSection(reader);
// // You can add custom processing code here.
//}
//protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
//{
// string s = base.SerializeSection(parentElement, name, saveMode);
// // You can add custom processing code here.
// return s;
//}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.