Skip to content

Commit 277a107

Browse files
committed
Tidy
1 parent 39cd706 commit 277a107

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
namespace FsCodec.SystemTextJson
22

3-
open System
4-
open System.Linq.Expressions
53
open System.Text.Json.Serialization
64

7-
type internal ConverterActivator = delegate of unit -> JsonConverter
8-
95
type UnionOrTypeSafeEnumConverterFactory(typeSafeEnum, union) =
106
inherit JsonConverterFactory()
117

12-
static let hasConverterAttribute = memoize (fun (t: Type) -> t.IsDefined(typeof<JsonConverterAttribute>, true))
8+
static let hasConverterAttribute = memoize (fun (t: System.Type) -> t.IsDefined(typeof<JsonConverterAttribute>, true))
139

14-
override _.CanConvert(t: Type) =
10+
override _.CanConvert t =
1511
not (t.IsGenericType && let gtd = t.GetGenericTypeDefinition() in gtd = typedefof<option<_>> || gtd = typedefof<list<_>>)
1612
&& FsCodec.Union.isUnion t
1713
&& not (hasConverterAttribute t)
@@ -20,9 +16,4 @@ type UnionOrTypeSafeEnumConverterFactory(typeSafeEnum, union) =
2016

2117
override _.CreateConverter(t, _options) =
2218
let openConverterType = if FsCodec.Union.isNullary t then typedefof<TypeSafeEnumConverter<_>> else typedefof<UnionConverter<_>>
23-
let constructor = openConverterType.MakeGenericType(t).GetConstructors() |> Array.head
24-
let newExpression = Expression.New(constructor)
25-
let lambda = Expression.Lambda(typeof<ConverterActivator>, newExpression)
26-
27-
let activator = lambda.Compile() :?> ConverterActivator
28-
activator.Invoke()
19+
openConverterType.MakeGenericType(t).GetConstructors().[0].Invoke[||] :?> _

0 commit comments

Comments
 (0)