diff --git a/CSharpRepl/Eval/ResultModels/EvalResult.cs b/CSharpRepl/Eval/ResultModels/EvalResult.cs index 8843420..bda5cc9 100644 --- a/CSharpRepl/Eval/ResultModels/EvalResult.cs +++ b/CSharpRepl/Eval/ResultModels/EvalResult.cs @@ -95,7 +95,7 @@ public override string ToString() new DirectoryInfoJsonConverter(), new AngouriMathEntityConverter(), new AngouriMathEntityVarsConverter(), new NumberConverter(), - new ByteEnumerableConverterFactory(), + new ByteEnumerableJsonConverter(), new MultidimArrayConverterFactory() } }); diff --git a/CSharpRepl/Infrastructure/JsonFormatters/TypeJsonConverter.cs b/CSharpRepl/Infrastructure/JsonFormatters/TypeJsonConverter.cs index bb18446..9c5d289 100644 --- a/CSharpRepl/Infrastructure/JsonFormatters/TypeJsonConverter.cs +++ b/CSharpRepl/Infrastructure/JsonFormatters/TypeJsonConverter.cs @@ -174,22 +174,17 @@ public override void Write(Utf8JsonWriter writer, DirectoryInfo value, JsonSeria writer.WriteStringValue(value.FullName); } } - - public class ByteEnumerableConverterFactory : JsonConverterFactory - { - public override bool CanConvert(Type typeToConvert) => typeToConvert.GetInterfaces().Contains(typeof(IEnumerable)); - public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) - => (JsonConverter)Activator.CreateInstance(typeof(ByteEnumerableJsonConverter<>).MakeGenericType(typeToConvert)); - } - public class ByteEnumerableJsonConverter : JsonConverter where T : IEnumerable + public class ByteEnumerableJsonConverter : JsonConverter> { - public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override bool CanConvert(Type typeToConvert) => typeToConvert.GetInterfaces().Contains(typeof(IEnumerable)); + + public override IEnumerable Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { throw new NotImplementedException(); } - public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, IEnumerable value, JsonSerializerOptions options) { ((JsonConverter>)options.GetConverter(typeof(IEnumerable))).Write(writer, value.Select(int (x) => x), options); } diff --git a/CSharpRepl/Startup.cs b/CSharpRepl/Startup.cs index 5519f9f..c70805e 100644 --- a/CSharpRepl/Startup.cs +++ b/CSharpRepl/Startup.cs @@ -44,7 +44,7 @@ public void ConfigureServices(IServiceCollection services) new DirectoryInfoJsonConverter(), new AngouriMathEntityConverter(), new AngouriMathEntityVarsConverter(), new NumberConverter(), - new ByteEnumerableConverterFactory(), + new ByteEnumerableJsonConverter(), new MultidimArrayConverterFactory() } }; @@ -72,7 +72,7 @@ public void ConfigureServices(IServiceCollection services) o.JsonSerializerOptions.Converters.Add(new AngouriMathEntityConverter()); o.JsonSerializerOptions.Converters.Add(new AngouriMathEntityVarsConverter()); o.JsonSerializerOptions.Converters.Add(new NumberConverter()); - o.JsonSerializerOptions.Converters.Add(new ByteEnumerableConverterFactory()); + o.JsonSerializerOptions.Converters.Add(new ByteEnumerableJsonConverter()); o.JsonSerializerOptions.Converters.Add(new MultidimArrayConverterFactory()); }); services.AddSingleton(jsonOptions);