BinarySerializer
BinarySerializer copied to clipboard
Proposal: FieldValueConverter
Adding Support for Complex Types as Serializable Properties.
For Implementation Reference:
-
Json.NET Custom JsonConverter: https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm.
-
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:
- Converting Long to IPAddress.
- Converting Int to TimeSpan.
Example Code:
[FieldOrder(1)] [FieldLength(32)] [IPAddressConverter] public IPAddress Address { get; set; }
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:
- Converting Long to IPAddress.
- 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.
The Json.NET approach have the following advantages:
- The default Serializer behavior is more than enough in most cases.
- The ability to change Serializer behavior on a Property-level instead of globally.
- Follows the library "Attribute" pattern.
- Forces cleaner code and separation of concerns.
- Provides extendable pattern when supporting many complex types without impacting Serializer performance.
- Some Types are sealed classes and can't be inherited with IBinarySerializable like TimeSpan.
Finally, Thanks for your cooperation and support.