-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config option to save DateTime and TimeOffset as Int64 #127
base: master
Are you sure you want to change the base?
Conversation
90acf3c
to
0cbe3cb
Compare
return fsResult.Success; | ||
} | ||
|
||
if (instance is DateTimeOffset) { | ||
var dateTimeOffset = (DateTimeOffset)instance; | ||
serialized = new fsData(dateTimeOffset.ToString(DateTimeOffsetFormatString)); | ||
serialized = new fsData(dateTimeOffset.Ticks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change intentional? The fsConfig comment implies that this should still be serialized as a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I honestly can't remember - I wrote this ages ago and forgot to submit a PR... it looks like I thought I had a reason for sticking to string for DateTimeOffset
. Maybe this code is just a left-over experiment? I'll have a look.
@@ -27,31 +27,45 @@ public class fsDateConverter : fsConverter { | |||
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) { | |||
if (instance is DateTime) { | |||
var dateTime = (DateTime)instance; | |||
serialized = new fsData(dateTime.ToString(DateTimeFormatString)); | |||
if(Serializer.Config.SerializeDateTimeAsInteger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if (
serialized = new fsData(dateTime.Ticks); | ||
} else { | ||
serialized = new fsData(dateTime.ToString(DateTimeFormatString)); | ||
return fsResult.Success; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop return (handled immediately below)
return fsResult.Success; | ||
} | ||
|
||
if (instance is TimeSpan) { | ||
var timeSpan = (TimeSpan)instance; | ||
serialized = new fsData(timeSpan.ToString()); | ||
if(Serializer.Config.SerializeDateTimeAsInteger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if (
return fsResult.Success; | ||
} | ||
|
||
throw new InvalidOperationException("FullSerializer Internal Error -- Unexpected serialization type"); | ||
} | ||
|
||
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) { | ||
if (data.IsString == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would drop all of the config checks in this function; deserialization should be successful regardless of the current config mode.
0cbe3cb
to
536311d
Compare
This PR seems to behavior changes even if a config flag is not swapped so I'll leave it open w/o merging for now. |
This is something I did a long time ago, to make date serialization faster and take less space once serialized.
It's not pretty code but it works - I'll leave it up to you to decide if it can be merged or not, or if it needs rework!
Edit: re-pushed with new formatting and tests namespace.