Type Convert Problem

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top