// Copyright Epic Games, Inc. All Rights Reserved. using System.Diagnostics.CodeAnalysis; using EpicGames.Core; namespace JsonExtensions { /// /// Extension methods for JsonObject to provide some deprecated field helpers /// public static class DeprecatedFieldHelpers { /// /// Tries to read a string array field by the given name from the object; if that's not found, checks for an older deprecated name /// /// JSON object to check /// Name of the field to get /// Backup field name to check /// On success, receives the field value /// True if the field could be read, false otherwise public static bool TryGetStringArrayFieldWithDeprecatedFallback(this JsonObject Obj, string FieldName, string DeprecatedFieldName, [NotNullWhen(true)] out string[]? Result) { if (Obj.TryGetStringArrayField(FieldName, out Result)) { return true; } else if (Obj.TryGetStringArrayField(DeprecatedFieldName, out Result)) { //@TODO: Warn here? return true; } else { return false; } } /// /// Tries to read an enum array field by the given name from the object; if that's not found, checks for an older deprecated name /// /// JSON object to check /// Name of the field to get /// Backup field name to check /// On success, receives the field value /// True if the field could be read, false otherwise public static bool TryGetEnumArrayFieldWithDeprecatedFallback(this JsonObject Obj, string FieldName, string DeprecatedFieldName, [NotNullWhen(true)] out T[]? Result) where T : struct { if (Obj.TryGetEnumArrayField(FieldName, out Result)) { return true; } else if (Obj.TryGetEnumArrayField(DeprecatedFieldName, out Result)) { //@TODO: Warn here? return true; } else { return false; } } } }