By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

Unexpected behavior: TypeConverter tc=TypeDescriptor.GetConverter(t);

P: n/a
kw
I'm getting different behavior from what I would expect and was hoping
someone could clue me in. At run time I need to examine a property of an
object for a custom TypeConverter, then use that converter on a value.

Here's the deal:

object[]
attrs=(object[])PropertyInfo.GetCustomAttributes(typeof(TypeConve rterAttribu
te),false);

TypeConverterAttribute a = (TypeConverterAttribute)attrs[0];

Type t=Type.GetType(a.ConverterTypeName);

//ok up to this point. Note that Type t is in an external assembly (it
shouldn't matter)

TypeConverter tc=TypeDescriptor.GetConverter(t);

Debug.WriteLine(tc.ConvertToString(this,vValue));

//it didn't work?! The TypeConverter never got invoked.

I'm getting different behavior from what I would expect and was hoping
someone could clue me in. At run time I need to examine a property of an
object for a custom TypeConverter, then use that converter on a value.

Not that it should matter, but the TypeConverter I use looks like this:
public class FormatCurrency : StringConverter{...}

And the object property looks like this:

[TypeConverter(typeof(MyNameSpace.FormatCurrency))]

public Double CurrencyWithTypeConverter{..}
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
kw
No, this is not the issue. Note that this line executes correctly:
Type t=Type.GetType(a.ConverterTypeName);

Thanks for trying :)

"Sijin Joseph" <si***************@hotmail.com> wrote in message
news:uI*************@TK2MSFTNGP11.phx.gbl...
If the TypeConverter is in a different assembly then you should use the
string overlaod of the TypeConverterAttribute ctor.

[TypeConverter("MyNameSpace.FormatCurrency")]
public Double CurrencyWithTypeConverter{..}

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

kw wrote:
I'm getting different behavior from what I would expect and was hoping
someone could clue me in. At run time I need to examine a property of an object for a custom TypeConverter, then use that converter on a value.

Here's the deal:

object[]
attrs=(object[])PropertyInfo.GetCustomAttributes(typeof(TypeConve rterAttribu te),false);

TypeConverterAttribute a = (TypeConverterAttribute)attrs[0];

Type t=Type.GetType(a.ConverterTypeName);

//ok up to this point. Note that Type t is in an external assembly (it
shouldn't matter)

TypeConverter tc=TypeDescriptor.GetConverter(t);

Debug.WriteLine(tc.ConvertToString(this,vValue));

//it didn't work?! The TypeConverter never got invoked.

I'm getting different behavior from what I would expect and was hoping
someone could clue me in. At run time I need to examine a property of an object for a custom TypeConverter, then use that converter on a value.

Not that it should matter, but the TypeConverter I use looks like this:
public class FormatCurrency : StringConverter{...}

And the object property looks like this:

[TypeConverter(typeof(MyNameSpace.FormatCurrency))]

public Double CurrencyWithTypeConverter{..}

Nov 16 '05 #2

P: n/a
kw
I found the solution:

TypeConverter tc=(TypeConverter)Activator.CreateInstance(t);

GetConverter() was the wrong approach.
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.