73 lines
2.6 KiB
C#
73 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
|
|
namespace CaeGlobals
|
|
{
|
|
public class StringStringDefaultConverter : TypeConverter
|
|
{
|
|
// Variables
|
|
private ArrayList values;
|
|
private string _default = "Default";
|
|
public static string InitialValue = "1";
|
|
|
|
|
|
// Constructors
|
|
public StringStringDefaultConverter()
|
|
{
|
|
// Initializes the standard values list with defaults.
|
|
values = new ArrayList(new string[] { null, InitialValue });
|
|
}
|
|
|
|
|
|
// Methods
|
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
|
{
|
|
return true;
|
|
}
|
|
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
{
|
|
// Passes the local integer array.
|
|
StandardValuesCollection svc = new StandardValuesCollection(values);
|
|
return svc;
|
|
}
|
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|
{
|
|
if (sourceType == typeof(string)) return true;
|
|
else return base.CanConvertFrom(context, sourceType);
|
|
}
|
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|
{
|
|
if (value.GetType() == typeof(string))
|
|
{
|
|
if (String.Equals(value, _default)) return null;
|
|
else return value;
|
|
}
|
|
else return base.ConvertFrom(context, culture, value);
|
|
}
|
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
|
{
|
|
// Convert to string
|
|
try
|
|
{
|
|
if (destinationType == typeof(string))
|
|
{
|
|
if (value == null) return _default;
|
|
else return value.ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
catch
|
|
{
|
|
return base.ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
} |