M
Michael Morse
Hello,
I beleive im having some troubles with the type converter within my server
control. I can pass into Type(s) of System.String, System.Boolean and even
custom classes that i've created myself but I cannot pass an enum. The goal
is that the end user developer can pass my control various different object
types.
Code is as follows:
public class SearchField
{
[TypeConverter(typeof(UtilTypeConverter))]
public Type SourceDataFieldType
{
get
{
if (this._dataType == null)
{
string typeName = (string)this._properties["SourceDataFieldType"];
this._dataType = (typeName == null) ? null : Type.GetType(typeName);
}
return this._dataType;
}
set
{
this._properties["SourceDataFieldType"] = value.ToString();
this._dataType = value;
}
}
}
public class UtilTypeConverter : TypeConverter
{
public UtilTypeConverter() { }
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
return ((sourceType == typeof(string)) || base.CanConvertFrom(context,
sourceType));
}
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value == null)
{
return null;
}
return Type.GetType((string)value);
}
}
Is there something special to take care of Enums? A little sample code or
comments will go a long way. Thank you!
I beleive im having some troubles with the type converter within my server
control. I can pass into Type(s) of System.String, System.Boolean and even
custom classes that i've created myself but I cannot pass an enum. The goal
is that the end user developer can pass my control various different object
types.
Code is as follows:
public class SearchField
{
[TypeConverter(typeof(UtilTypeConverter))]
public Type SourceDataFieldType
{
get
{
if (this._dataType == null)
{
string typeName = (string)this._properties["SourceDataFieldType"];
this._dataType = (typeName == null) ? null : Type.GetType(typeName);
}
return this._dataType;
}
set
{
this._properties["SourceDataFieldType"] = value.ToString();
this._dataType = value;
}
}
}
public class UtilTypeConverter : TypeConverter
{
public UtilTypeConverter() { }
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
return ((sourceType == typeof(string)) || base.CanConvertFrom(context,
sourceType));
}
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value == null)
{
return null;
}
return Type.GetType((string)value);
}
}
Is there something special to take care of Enums? A little sample code or
comments will go a long way. Thank you!