using System;
using System.ComponentModel;
namespace AnticipatingMinds.PlatformServices.Configuration{
/// <summary>
/// Summary description for ConfigurationSectionArrayConverter.
/// </summary>
public class ConfigurationSectionArrayConverter : ArrayConverter
{
protected class ConfigurationSectionPropertyDescription : SimplePropertyDescriptor
{
public ConfigurationSectionPropertyDescription(Array value,int elementIndex):base(value.GetType(),elementIndex.ToString(),value.GetType().GetElementType())
{
this.propertyType = value.GetType().GetElementType();
this.elementIndex = elementIndex;
}
public override object GetValue(object component)
{
return (component as ConfigurationSection[])[elementIndex];
}
public override void SetValue(object component,object value)
{
(component as ConfigurationSection[])[elementIndex] = value as ConfigurationSection;
}
public override string DisplayName
{
get
{
DisplayNameAttribute[] displayNames = propertyType.GetCustomAttributes(typeof(DisplayNameAttribute),false)as DisplayNameAttribute[];
if(displayNames.Length != 0)
return displayNames[0].DisplayName;
return base.DisplayName;
}
}
public override string Description
{
get
{
DescriptionAttribute[] displayNames = propertyType.GetCustomAttributes(typeof(DescriptionAttribute),false)as DescriptionAttribute[];
if(displayNames.Length != 0)
return displayNames[0].Description;
return base.Description;
}
}
private int elementIndex;
private Type propertyType;
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return context.PropertyDescriptor.Description;
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
PropertyDescriptorCollection properties = new PropertyDescriptorCollection(new ConfigurationPropertyDescription[0]);
for(int propertyIndex = 0; propertyIndex < (value as Array).Length; propertyIndex++)
properties.Add(new ConfigurationSectionPropertyDescription((value as Array),propertyIndex));
//properties = base.GetProperties(context, value,attributes);
return properties;
}
}
}
|