Re: Using custom TypeConverter outside of PropertyGrid
- From: Cartoper <cartoper@xxxxxxxxx>
- Date: Fri, 28 Mar 2008 10:54:57 -0700 (PDT)
As I walked to lunch it dawned on me that I might be able to get at
the attributes via the GetType() method. Well, I wasn't able to, but
I did realize that as long as you follow the convention of <enum
name>TypeConverter, that through reflections you can instanciate the
enum's TypeConverter:
// start by using the default ToString method
string valueStr = Value.ToString();
try
{
// Get the enum type
Type enumType = Value.GetType();
// Get the enum name and then add the TypeConverter to the end of it
string typeConverterName = enumType.FullName + "TypeConverter";
// Get the assembly that the enum is in.
string assemblyName = enumType.Assembly.FullName;
// try to create the type converter
ObjectHandle objHandle =
Thread.GetDomain().CreateInstance(assemblyName, typeConverterName);
// Get the TypeConverter from the object handle
TypeConverter typeConverter = objHandle.Unwrap() as TypeConverter;
// Convert it to a string
valueStr = typeConverter.ConvertToString(Value);
}
catch(Exception)
{
}
.
- Follow-Ups:
- Re: Using custom TypeConverter outside of PropertyGrid
- From: Marc Gravell
- Re: Using custom TypeConverter outside of PropertyGrid
- References:
- Using custom TypeConverter outside of PropertyGrid
- From: Cartoper
- Using custom TypeConverter outside of PropertyGrid
- Prev by Date: Re: windows forms - transparence question
- Next by Date: Re: How can I prevent someone run a "HEX modified" executable ?
- Previous by thread: Using custom TypeConverter outside of PropertyGrid
- Next by thread: Re: Using custom TypeConverter outside of PropertyGrid
- Index(es):
Relevant Pages
|