BinarySerializer icon indicating copy to clipboard operation
BinarySerializer copied to clipboard

Proposal: FieldValueConverter

Open Texnomic opened this issue 6 years ago • 2 comments

Adding Support for Complex Types as Serializable Properties.

For Implementation Reference:

  1. Json.NET Custom JsonConverter: https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm.

  2. System.Text.Json.Serialization JsonConverter<T> https://docs.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonconverter-1?view=netcore-3.0

Example Usage:

  1. Converting Long to IPAddress.
  2. Converting Int to TimeSpan.

Example Code:

[FieldOrder(1)] [FieldLength(32)] [IPAddressConverter] public IPAddress Address { get; set; }

Texnomic avatar Jun 04 '19 22:06 Texnomic

This is currently supported through custom serialization (implementing IBinarySerializable). If there’s a better way I’m willing to consider it but I need to understand the advantages.


From: Mohamed Samy [email protected] Sent: Tuesday, June 4, 2019 6:08 PM To: jefffhaynes/BinarySerializer Cc: Subscribed Subject: [jefffhaynes/BinarySerializer] ValueConverter (#127)

Adding Support for Complex Types as Serializable Properties.

For Implementation Reference, Json.NET Custom JsonConverter: https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm.

Example Usage:

  1. Converting Long to IPAddress.
  2. Converting Int to TimeSpan.

Example Code:

[FieldOrder(1)] [FieldLength(32)] [IPAddressConverter] public IPAddress Address { get; set; }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/BinarySerializer/issues/127?email_source=notifications&email_token=ACKIURZ7BR6EIFWJYIZKD3TPY3RVLA5CNFSM4HTFEI72YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GXUPGRQ, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACKIUR4J2HLBIM5VJDXTXWDPY3RVLANCNFSM4HTFEI7Q.

jefffhaynes avatar Jun 06 '19 23:06 jefffhaynes

The Json.NET approach have the following advantages:

  1. The default Serializer behavior is more than enough in most cases.
  2. The ability to change Serializer behavior on a Property-level instead of globally.
  3. Follows the library "Attribute" pattern.
  4. Forces cleaner code and separation of concerns.
  5. Provides extendable pattern when supporting many complex types without impacting Serializer performance.
  6. Some Types are sealed classes and can't be inherited with IBinarySerializable like TimeSpan.

Finally, Thanks for your cooperation and support.

Texnomic avatar Jun 08 '19 02:06 Texnomic