leejw51 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

TypeConverter Support for V1 Patch #124

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Attached is a patch that adds support for type converters.

If there is a type converter for a property with an otherwise unknown type that 
can convert to Int32 then it will be used instead of blowing up.

It also will be used for the default value support as well.

Original issue reported on code.google.com by bryanliv...@gmail.com on 28 Jul 2010 at 9:11

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks; an interesting patch. What types/use-cases did you have in mind for 
this?

One of the problems with that approach is that it doesn't apply to all the 
frameworks that protobuf-net currently targets. I wonder if long-term, the "v2" 
support for proxy types via conversion operators is a better option.

Original comment by marc.gravell on 29 Jul 2010 at 5:55

GoogleCodeExporter commented 9 years ago
I use it to serialize WPF Color structs as integers on my web template designer 
site at http://cooltemplate.com

Done another way for V2 would be great, I just couldn't afford to wait for it 
any longer.

Original comment by bryanliv...@gmail.com on 8 Sep 2010 at 4:41

GoogleCodeExporter commented 9 years ago
Marc, did you already find another way to do this? I would also like to send 
Windows.Media.Color properties.
Thanks, Erik

Original comment by Erik.Vul...@gmail.com on 25 May 2011 at 9:49

GoogleCodeExporter commented 9 years ago
@Erik - the simplest way to do this remains being simply adding a separate 
property that formats/parses the data in whatever way you choose, and mark the 
*second* property for serialization. This property can be private for regular 
.NET.

In v2, I've added 2 examples of doing this in v2, here: 
http://code.google.com/p/protobuf-net/source/browse/trunk/Examples/Issues/Issue1
24.cs

(you can apply this to the RuntimeTypeModel.Default too, which works with the 
static methods, but I needed separate models for 2 different tests)

Original comment by marc.gravell on 26 May 2011 at 9:36

GoogleCodeExporter commented 9 years ago
@Erik - the simplest way to do this remains being simply adding a separate 
property that formats/parses the data in whatever way you choose, and mark the 
*second* property for serialization. This property can be private for regular 
.NET.

In v2, I've added 2 examples of doing this in v2, here: 
http://code.google.com/p/protobuf-net/source/browse/trunk/Examples/Issues/Issue1
24.cs

(you can apply this to the RuntimeTypeModel.Default too, which works with the 
static methods, but I needed separate models for 2 different tests)

Original comment by marc.gravell on 26 May 2011 at 9:36

GoogleCodeExporter commented 9 years ago
@Marc - thanks for the tip. I already implemented a similar solution (using a 
byte[] of size 4), but it's good to know that it can also be a private 
property. 

Original comment by Erik.Vul...@gmail.com on 27 May 2011 at 1:10

GoogleCodeExporter commented 9 years ago
That example looks awesome!  Can't wait until V2 ships so that I can use it.

Thanks again for all your hard work Marc!

Original comment by bryanliv...@gmail.com on 8 Jun 2011 at 11:03

GoogleCodeExporter commented 9 years ago
v2 is available for download (albeit marked beta) *now*. The "beta" branding is 
mainly due to needing to add the side services (GetProto, extension-data etc). 
The core is stable.

Original comment by marc.gravell on 9 Jun 2011 at 11:26