From 3044a2bc819aff2ef827fdab524d5bbce2f4e2e1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 22 Nov 2020 16:57:44 +0100 Subject: [PATCH] allow using a custom json serializer for LoadJson --- MLEM.Data/ContentExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MLEM.Data/ContentExtensions.cs b/MLEM.Data/ContentExtensions.cs index 7fc4165..2801a20 100644 --- a/MLEM.Data/ContentExtensions.cs +++ b/MLEM.Data/ContentExtensions.cs @@ -53,10 +53,12 @@ namespace MLEM.Data { /// The content manager to load content with /// The name of the file to load /// The file extensions that should be appended, or ".json", ".json5" and ".jsonc" by default. + /// The json serializer to use, or by default. /// The type of asset to load /// The loaded asset - public static T LoadJson(this ContentManager content, string name, string[] extensions = null) { + public static T LoadJson(this ContentManager content, string name, string[] extensions = null, JsonSerializer serializer = null) { var triedFiles = new List(); + var serializerToUse = serializer ?? content.GetJsonSerializer(); foreach (var extension in extensions ?? JsonExtensions) { var file = Path.Combine(content.RootDirectory, name + extension); triedFiles.Add(file); @@ -64,7 +66,7 @@ namespace MLEM.Data { continue; using (var stream = File.OpenText(file)) { using (var reader = new JsonTextReader(stream)) { - return GetJsonSerializer(content).Deserialize(reader); + return serializerToUse.Deserialize(reader); } } }