473,738 Members | 3,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unexpected behavior: TypeConverter tc=TypeDescript or.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.G etCustomAttribu tes(typeof(Type ConverterAttrib u
te),false);

TypeConverterAt tribute a = (TypeConverterA ttribute)attrs[0];

Type t=Type.GetType( a.ConverterType Name);

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

TypeConverter tc=TypeDescript or.GetConverter (t);

Debug.WriteLine (tc.ConvertToSt ring(this,vValu e));

//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(t ypeof(MyNameSpa ce.FormatCurren cy))]

public Double CurrencyWithTyp eConverter{..}
Nov 16 '05 #1
2 3419
kw
No, this is not the issue. Note that this line executes correctly:
Type t=Type.GetType( a.ConverterType Name);

Thanks for trying :)

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

[TypeConverter(" MyNameSpace.For matCurrency")]
public Double CurrencyWithTyp eConverter{..}

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.G etCustomAttribu tes(typeof(Type ConverterAttrib u te),false);

TypeConverterAt tribute a = (TypeConverterA ttribute)attrs[0];

Type t=Type.GetType( a.ConverterType Name);

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

TypeConverter tc=TypeDescript or.GetConverter (t);

Debug.WriteLine (tc.ConvertToSt ring(this,vValu e));

//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(t ypeof(MyNameSpa ce.FormatCurren cy))]

public Double CurrencyWithTyp eConverter{..}

Nov 16 '05 #2
kw
I found the solution:

TypeConverter tc=(TypeConvert er)Activator.Cr eateInstance(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
5078
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 Martin
4
391
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 struct would look more or less like: struct MySum<T> where T : struct { public static T AddInteger(T value, int i) { return value + i;
1
1367
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 where it is used so I hopefully understand it better. TypeConverter IntConverter = TypeDescriptor.GetConverter(typeof(Int32));
4
1701
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
4601
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
3892
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 "GetProperites()" method so why complicate the situation even more than it already is by adding a "GetProperties()" method to "TypeConverter". The class is supposed to be for converting types so "GetProperties()" seems misplaced and redundant (as...
4
3316
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.. but I'm digressing) In this XML file I store object value, which I convert to string (when writting) and from string (when reading) with a couple of simple function which (should) do a reversible conversion (using TypeConverter) (functions...
1
2168
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 PropertyDescriptor class were overridden. But for a dropdown list I needed the COnverter method also, but I dont know how I would do it? eg.
3
1902
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 text file, in a generic fashion. I would like to have a function like this: void WriteValue(StreamWriter sw, string name, Enum value);
0
8968
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8208
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.