Hi Kerry,
The .NET Framework provides the following two mechanisms for converting
user-defined data types (custom types) to other data types:
1. Extending TypeConverter class
2. Implementing the System.IConvertible interface
For more information about the comparison of these 2 mechanisms, please
refer to:
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpcongeneralizedtypeconversion.asp
For your problem about extend TypeConverter class, there is a general
article talks about implement of TypeConverter's members, please refer to :
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconimplementingtypeconverter.asp
Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: Kerry Sanders <di****@NOSPAMyahoo.com>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: Issue implementing type converter
| Reply-To:
di****@NOSPAMyahoo.com
| Message-ID: <if********************************@4ax.com>
| X-Newsreader: Forte Agent 1.93/32.576 English (American)
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 69
| X-Trace:
ldjgbllpbapjglppdbdpiflmbcekedmfhojhikkbagflhcbofa chioobchmjnfogjaaegiopdjee
lgcighdcopgoocdmbhomolbaoecancgepjpmkamohehnohkmch jekkahbepaapmgfphnfhmnjcld
kjelblnp
| NNTP-Posting-Date: Sat, 25 Oct 2003 23:08:20 EDT
| Date: Sat, 25 Oct 2003 22:10:31 -0500
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTN GP08.phx.gbl!newsfeed00.su
l.t-online.de!t-online.de!news-lei1.dfn.de!newsfeed.freenet.de!newsfeed.news
2me.com!newsfeed2.easynews.com!newsfeed1.easynews. com!easynews.com!easynews!
bigfeed2.bellsouth.net!bigfeed.bellsouth.net!bignu mb.bellsouth.net!news.bell
south.net!bignews5.bellsouth.net.POSTED!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:194102
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I am working on a project for work where I need a specialized type
| converter to convert the value of a string which is edited in a grid
| back to the underlying object type from the cell. The value in the
| cell is displayed as a string from the ToString() method in the class.
|
| Anyway, I am trying to implement my converter, but I am having a
| little trouble understanding it fully and how exactly to implement
| some of the methods, especially the ConvertFrom and whether or not I
| have properly implemented the CreateInstance method.
|
| I have written some code below. This code is not the actual code, but
| it gives a good representation of what I am trying to do.
|
| Can someone give me some help on this?
|
|
| public class PizzaConverter : ExpandableObjectConverter
| {
| public override bool
| GetCreateInstanceSupported(ITypeDescriptorContext context)
| {
| return true;
| }
|
| public override object CreateInstance(ITypeDescriptorContext
| context, IDictionary propertyValues)
| {
| return new Pizza((string)propertyValues["Maker"],
| (int)propertyValues["NumberOfPizzas"]);
| }
|
| public override bool CanConvertFrom(ITypeDescriptorContext
| context, Type sourceType)
| {
| if (sourceType == typeof(string))
| return true;
| return base.CanConvertFrom (context, sourceType);
| }
|
| public override object ConvertFrom(ITypeDescriptorContext
| context, System.Globalization.CultureInfo culture, object value)
| {
| }
| }
|
| [TypeConverter(typeof(PizzaConverter))]
| public class Pizza
| {
| public Pizza(string PizzaMaker, int NumberOrdered)
| {
| Maker = PizzaMaker;
| NumberOfPizzas = NumberOrdered;
| }
|
| private string sMaker = "";
| public string Maker
| {
| get { return this.sMaker; }
| set { this.sMaker = value; }
| }
|
| private int mNumberOfPizzas = 0;
| public int NumberOfPizzas
| {
| get { return this.mNumberOfPizzas; }
| set { this.mNumberOfPizzas = value; }
| }
| }
|
|