mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
allow using a custom json serializer for LoadJson
This commit is contained in:
parent
6e7720295f
commit
3044a2bc81
1 changed files with 4 additions and 2 deletions
|
@ -53,10 +53,12 @@ namespace MLEM.Data {
|
|||
/// <param name="content">The content manager to load content with</param>
|
||||
/// <param name="name">The name of the file to load</param>
|
||||
/// <param name="extensions">The file extensions that should be appended, or ".json", ".json5" and ".jsonc" by default.</param>
|
||||
/// <param name="serializer">The json serializer to use, or <see cref="GetJsonSerializer"/> by default.</param>
|
||||
/// <typeparam name="T">The type of asset to load</typeparam>
|
||||
/// <returns>The loaded asset</returns>
|
||||
public static T LoadJson<T>(this ContentManager content, string name, string[] extensions = null) {
|
||||
public static T LoadJson<T>(this ContentManager content, string name, string[] extensions = null, JsonSerializer serializer = null) {
|
||||
var triedFiles = new List<string>();
|
||||
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<T>(reader);
|
||||
return serializerToUse.Deserialize<T>(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue