using System;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design;
using AnticipatingMinds.Genesis.KnowledgeManagement;
namespace AnticipatingMinds.Genesis.KnowledgeManagement.KnowledgeBaseUI{
//This type converter is read only
//it only shows string that enumerates all profiles it does not
//assign or edit the values
//to edit values use [EditorAttribute(typeof(ProfilesArrayUIEditor),typeof(System.Drawing.Design.UITypeEditor))]
//attribute
public class ProfilesArrayReadOnlyTypeConverter : TypeConverter
{
public ProfilesArrayReadOnlyTypeConverter()
{
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return false;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if(destinationType != typeof(string))
return false;
if(!(context.Instance is Array))
return false;
if(context.Instance.GetType().GetElementType() != typeof(Profile))
return false;
return true;
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(string) && value is Array)
{
Profile[] profiles = value as Profile[];
if(profiles == null || profiles.Length == 0)
return "(default)";
StringBuilder profilesListBuilder = new StringBuilder(profiles[0].Name);
for(int profileIndex = 1; profileIndex < profiles.Length; profileIndex++)
profilesListBuilder.Append(", ").Append(profiles[profileIndex].Name);
return profilesListBuilder.ToString();
}
return string.Empty;
}
}
}
|