Skip to content

Commit ca01ebb

Browse files
committed
chore: Minor Formatting/cleanup
1 parent 8ddaf27 commit ca01ebb

5 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/FsCodec.NewtonsoftJson/UnionConverter.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module private UnionInfo =
1313
t = typeof<string>
1414
|| t.IsValueType
1515
|| t.IsArray
16-
|| (t.IsGenericType && let g = t.GetGenericTypeDefinition() in typedefof<Option<_>> = g || g.IsValueType) // Nullable<T>
16+
|| (t.IsGenericType && let g = t.GetGenericTypeDefinition() in typedefof<option<_>> = g || g.IsValueType) // Nullable<T>, ValueOption<T>
1717

1818
let hasConverterCache = System.Collections.Concurrent.ConcurrentDictionary<Type, bool>()
1919
let typeHasConverterAttribute (t: Type) = hasConverterCache.GetOrAdd(t, fun t -> t.IsDefined(typeof<JsonConverterAttribute>, ``inherit`` = false))

src/FsCodec.SystemTextJson/Options.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ type Options private () =
7070
if rejectNullStrings then RejectNullStringConverter()
7171
if autoTypeSafeEnumToJsonString || autoUnionToJsonObject then
7272
UnionOrTypeSafeEnumConverterFactory(typeSafeEnum = autoTypeSafeEnumToJsonString, union = autoUnionToJsonObject)
73-
if converters <> null then yield! converters
74-
|],
73+
if converters <> null then yield! converters |],
7574
?ignoreNulls = ignoreNulls,
7675
?indent = indent,
7776
?camelCase = camelCase,

src/FsCodec.SystemTextJson/RejectNullStringConverter.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type RejectNullStringConverter() =
66
let [<Literal>] message = "Expected string, got null. When allowNullStrings is false you must explicitly type optional strings as 'string option'"
77

88
override _.HandleNull = true
9-
override _.CanConvert(t) = t = typeof<string>
9+
override _.CanConvert t = t = typeof<string>
1010

1111
override this.Read(reader, _typeToConvert, _options) =
1212
let value = reader.GetString()
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
namespace FsCodec.SystemTextJson
22

3-
open System
43
open System.Text.Json
54

65
/// Maps strings to/from Union cases; refuses to convert for values not in the Union
76
type TypeSafeEnumConverter<'T>() =
87
inherit Serialization.JsonConverter<'T>()
98

10-
override _.CanConvert(t: Type) =
11-
let tt = typedefof<'T>
12-
t = tt && FsCodec.Union.isUnion tt && FsCodec.Union.isNullary tt
9+
override _.CanConvert t =
10+
t = typeof<'T> && FsCodec.Union.isUnion t && FsCodec.Union.isNullary t
1311

1412
override _.Write(writer, value, _options) =
15-
let str = FsCodec.TypeSafeEnum.toString value
16-
writer.WriteStringValue str
13+
value |> FsCodec.TypeSafeEnum.toString |> writer.WriteStringValue
1714

1815
override _.Read(reader, _t, _options) =
1916
if reader.TokenType <> JsonTokenType.String then
2017
sprintf "Unexpected token when reading TypeSafeEnum: %O" reader.TokenType |> JsonException |> raise
21-
let str = reader.GetString()
22-
FsCodec.TypeSafeEnum.parse<'T> str
18+
reader.GetString() |> FsCodec.TypeSafeEnum.parse<'T>

src/FsCodec.SystemTextJson/UnionConverter.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type UnionConverter<'T>() =
2626
let converterOptions = UnionConverterOptions.get typeof<'T>
2727
let info = FsCodec.Union.Info.get typeof<'T>
2828

29-
override _.CanConvert(t: Type) = t = typeof<'T> && FsCodec.Union.isUnion t
29+
override _.CanConvert t = t = typeof<'T> && FsCodec.Union.isUnion t
3030

3131
override _.Write(writer: Utf8JsonWriter, value, options: JsonSerializerOptions) =
3232
let value = box value
@@ -59,7 +59,7 @@ type UnionConverter<'T>() =
5959
match findCaseNamed inputCaseNameValue, converterOptions.CatchAllCase with
6060
| None, null ->
6161
sprintf "No case defined for '%s', and no catchAllCase nominated for '%s' on type '%s'"
62-
inputCaseNameValue typeof<UnionConverter<_>>.Name t.FullName |> invalidOp
62+
inputCaseNameValue typeof<UnionConverter<'T>>.Name t.FullName |> invalidOp
6363
| Some c, _ -> c
6464
| None, catchAllCaseName ->
6565
match findCaseNamed catchAllCaseName with

0 commit comments

Comments
 (0)