public static T Deserialize <T>(this IConfiguration config, IServiceProvider serviceProvider = default) { config.EnsureNotNull(nameof(config)); // T result; using (var reader = ToJsonReader(config: config, serviceProvider: serviceProvider)) { var serializerSettings = EonJsonUtilities.CreateDefaultSerializerSettings(); serializerSettings.TypeNameHandling = TypeNameHandling.All; serializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.All; var serializer = JsonSerializer.Create(settings: serializerSettings); result = serializer.Deserialize <T>(reader: reader.Value); } return(result); }
// TODO: Put strings into the resources. // public static T DeserializeJson <T>(this IConfiguration config, IServiceProvider serviceProvider = default, Func <JsonSerializerSettings, JsonSerializerSettings> configSettings = default) { config.EnsureNotNull(nameof(config)); // T result; using (var reader = ToJsonReader(config: config, serviceProvider: serviceProvider)) { var serializerSettings = EonJsonUtilities.CreateDefaultSerializerSettings(); serializerSettings.TypeNameHandling = TypeNameHandling.All; serializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.All; if (!(configSettings is null)) { serializerSettings = configSettings(arg: serializerSettings); if (serializerSettings is null) { throw new EonException(message: $"The method has returned an invalid result '{serializerSettings.FmtStr().G()}'.{Environment.NewLine}\tMethod:{configSettings.FmtStr().GNLI2()}"); } } var serializer = JsonSerializer.Create(settings: serializerSettings); result = serializer.Deserialize <T>(reader: reader.Value); } return(result); }