473,399 Members | 2,146 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,399 software developers and data experts.

TypeConverter.CanConvertTo()

Hi there,

Can someone confirm the correct use of a "TypeConverter.CanConvertTo()" override as it applies to string conversions. The canonical example looks like this:

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
else
{
return base.CanConvertTo(context, destinationType);
}
}

Two confusing issues exist however:

1) This never actually gets called. Based on what I'ver read, I think string conversions are always permitted so the system has no reason to call it (and therefore never does). Can someone confirm this and if so, why do so many examples on the web (including MSFT's) code things this way if it's never actually called.

2) I've seen other examples from senior MSFT staff where they don't actually test for "typeof(string)" as seen above. Instead, they test for the class this "TypeConverter" derivative was created for. That seems to make little sense (testing if a class can be converted to itself) and moreover, in the corresponding "ConvertTo()" override, they convert it to a string anyway. Can anyone explain this. Thanks.
Apr 10 '07 #1
0 2037

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

Similar topics

0
by: Peter Morris | last post by:
Hi all I created Collection + CollectionItem classes and a TypeConverter in order to persist the items in the collection. I then added descendants of these classes (ImageCollection, ImageItem)....
2
by: Joăo Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New...
0
by: Joăo Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New...
2
by: kw | last post by:
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...
2
by: Benny C. Mildh | last post by:
Hi! I'm trying to implement my own CanConvertTo-method from the derived TypeConverter class. Public Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType...
0
by: Eric Hoch | last post by:
Hello, I'm writing a TypeConverter for a class which inherits arraylist, but deserializing it always results in an arraylist, which causes an InvalidCastException. If anyone can point out what...
4
by: Kent Boogaart | last post by:
*tried this already on the buildingcontrols newsgroup but didn't get a response* Hi, As far as I can tell, it is not possible to use the TypeConverter infrastructure with generic types. Say...
11
by: Rolf Welskes | last post by:
Hello, the problem seems to be complex and is in all developments of web-controls which uses own TypeConverter. For this I have here a simple demo-program of the problem: The Control-code: A...
1
by: --== Alain ==-- | last post by:
Hi, I 'm facing an interesting issue regarding a property and its TypeConverter. When i do not attach a TypeConverter to this property, all custom properties of my custom control are displayed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.