11namespace FsCodec.SystemTextJson
22
3- open System
4- open System.Linq .Expressions
53open System.Text .Json .Serialization
64
7- type internal ConverterActivator = delegate of unit -> JsonConverter
8-
95type 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