C Programming Tutorials and advice
CProgrammingTrends News Archives About Us Feedback


Recent Articles


Rational Betas Have C++ Goodies
Features in the Rational Software Architect v7.0 beta include improved support for C++, and developers can try out the open beta by pre-registering for it with IBM.

Revisiting C/C++ On Eclipse
The tutorial from IBM's developerWorks on using the C/C++ Development Toolkit (CDT) for Eclipse received...

Using Immediate Window to Work with Values
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005.

C++ - No Fears And Great Books
This is a quick look at a couple of stories on C++, namely why programmers should not feel The Fear...

New NetBeans Pack Supports C/C++
Developers who work in C or C++ can use the NetBeans integrated developer environment to build applications on Windows, Linux, and Solaris.


Managed Hosting Solutions Powered By Rackspace
10.12.06


Assigning A TypeConverter To A Class You Don't Own


By Paul Kinlan

I ran into problems with the XNA Beta1, where by I had a class that had a Vector2 struct in.

The problem with the XNA Vector2 struct is that there is no TypeConverter for it at the moment. This means that there is no support in the designer.

I initially solved this problem by assigning a type converter to the public property on my class that used the Vector2. (see below)



However, VS2005, when serializing out to code from the designer, it will not obey the TypeConverter on the property, but will try to use the Type's Conveter eventhough the designer will use the TypeConverter on your class to edit the control... clear as mud? :)

This leads to ugly code in the InitializeCode method that tries to look in the resource file to get the object out. I didn't like this solution because it looks ugly and is hard to maintain.

Managed Hosting Solutions Powered By Rackspace

I solved this problem by forcing the TypeConverter on to the Vector2. In my classes constructor I called the following code I have created.



The above code adds the TypeConverter (TC) to the Type (T) so that the designer can serialize to code correctly using my own TypeConverter. The main thing it is doing is calling: TypeDescriptor.AddAttributes

The solution then allows the Designer to serialize to code and it gets rid of having to serialize the object to a resource file. The solution would look like the code below.



About the Author:
Paul Kinlan is the author of the popular C#, .Net Framework blog. Paul is an Analyst Developer working in Southport, England. Paul has several years experience developing and designing massively scalable enterprise systems on UNIX and Windows based architectures.

About CProgrammingTrends
A collection of articles and tutorials designed to help C and C variant programmers in their programming work. C Programming Tutorials and advice

CProgrammingTrends is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagmentNews.com


-- CProgrammingTrends is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2006 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal


archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


">Unsubscribe from CProgrammingTrends.
To unsubscribe from CProgrammingTrends or any other iEntry publication, simply send an email request to: support@ientry.com
CProgrammingTrends Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact