diff --git a/src/FsCodec.SystemTextJson/UnionOrTypeSafeEnumConverterFactory.fs b/src/FsCodec.SystemTextJson/UnionOrTypeSafeEnumConverterFactory.fs index f6eba02..0ea6c73 100644 --- a/src/FsCodec.SystemTextJson/UnionOrTypeSafeEnumConverterFactory.fs +++ b/src/FsCodec.SystemTextJson/UnionOrTypeSafeEnumConverterFactory.fs @@ -1,18 +1,14 @@ namespace FsCodec.SystemTextJson -open System -open System.Linq.Expressions open System.Text.Json.Serialization -type internal ConverterActivator = delegate of unit -> JsonConverter - type UnionOrTypeSafeEnumConverterFactory(typeSafeEnum, union) = inherit JsonConverterFactory() - static let hasConverterAttribute = memoize (fun (t: Type) -> t.IsDefined(typeof, true)) + static let hasConverterAttribute = memoize (fun (t: System.Type) -> t.IsDefined(typeof, true)) - override _.CanConvert(t: Type) = - not (t.IsGenericType && let gtd = t.GetGenericTypeDefinition() in gtd = typedefof> || gtd = typedefof>) + override _.CanConvert t = + not (t.IsGenericType && let g = t.GetGenericTypeDefinition() in g = typedefof> || g = typedefof>) && FsCodec.Union.isUnion t && not (hasConverterAttribute t) && ((typeSafeEnum && union) @@ -20,9 +16,4 @@ type UnionOrTypeSafeEnumConverterFactory(typeSafeEnum, union) = override _.CreateConverter(t, _options) = let openConverterType = if FsCodec.Union.isNullary t then typedefof> else typedefof> - let constructor = openConverterType.MakeGenericType(t).GetConstructors() |> Array.head - let newExpression = Expression.New(constructor) - let lambda = Expression.Lambda(typeof, newExpression) - - let activator = lambda.Compile() :?> ConverterActivator - activator.Invoke() + openConverterType.MakeGenericType(t).GetConstructors().[0].Invoke[||] :?> _