473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
2 3400
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
kw
I found the solution:

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

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Montgomery | last post by:
I have, for example, a property called myProperty. I would like, when using a property grid to display the property name as "My Property". Is this possible. Is there an attribute etc Thank ...
4
by: Tom Jastrzebski | last post by:
Hello everybody, Here is the problem I came across experimenting with Generics. I would like to write a class or a struct adding integer to any other, initially undefined *numeric type*. So, my...
1
by: tony | last post by:
Hello! I find it hard to understand this about TypeConverter. I have read some documentation but still it's hard to understand. For example this row below. Can somebody write some small code...
4
by: swartzbill2000 | last post by:
Hello, I have a TypeConverter for converting between this Enum and Strings. Public Enum DeviceNameEnum dnNone dn2500 dnMirror End Enum 'DeviceNameEnum
2
by: Robert Ludig | last post by:
I have class that has a property wich has a custom typeconverter: class A { private string _property; public string Property { get { return _property; } }
6
by: Larry Smith | last post by:
Hi there, Can anyone provide any insight on why MSFT introduced "TypeConverter.GetProperties()". There are two classes for dealing with metadata in .NET, 'Type" and "TypeDescriptor". Each has a...
4
by: Lloyd Dupont | last post by:
to store user preference in our application we have an 'hand written' XML file. (as opposed to XmlSerializer written one, which crash sometimes, on some user's computer, for some unknown reason.....
1
by: moni | last post by:
PropertyDescriptor Class has a Converter method, which if overriden, would return a TypeConverter. I was working on dynamic values for a propertygrid, so for each property all the methods of the...
3
by: Cartoper | last post by:
I have written all these wonderful custom TypeConverter for my enums to display in a PropertyGrid. I would now like to use the same TypeConverter to save out and read in the values to and from a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.