Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/System/JsonExtensions.cs
Marc Audy 0c3be2b6ad Merge Release-Engine-Staging to Test @ CL# 18240298
[CL 18241953 by Marc Audy in ue5-release-engine-test branch]
2021-11-18 14:37:34 -05:00

68 lines
2.2 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Linq;
using EpicGames.Core;
using System.Diagnostics.CodeAnalysis;
namespace JsonExtensions
{
/// <summary>
/// Extension methods for JsonObject to provide some deprecated field helpers
/// </summary>
public static class DeprecatedFieldHelpers
{
/// <summary>
/// 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
/// </summary>
/// <param name="Obj">JSON object to check</param>
/// <param name="FieldName">Name of the field to get</param>
/// <param name="DeprecatedFieldName">Backup field name to check</param>
/// <param name="Result">On success, receives the field value</param>
/// <returns>True if the field could be read, false otherwise</returns>
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;
}
}
/// <summary>
/// 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
/// </summary>
/// <param name="Obj">JSON object to check</param>
/// <param name="FieldName">Name of the field to get</param>
/// <param name="DeprecatedFieldName">Backup field name to check</param>
/// <param name="Result">On success, receives the field value</param>
/// <returns>True if the field could be read, false otherwise</returns>
public static bool TryGetEnumArrayFieldWithDeprecatedFallback<T>(this JsonObject Obj, string FieldName, string DeprecatedFieldName, [NotNullWhen(true)] out T[]? Result) where T : struct
{
if (Obj.TryGetEnumArrayField<T>(FieldName, out Result))
{
return true;
}
else if (Obj.TryGetEnumArrayField<T>(DeprecatedFieldName, out Result))
{
//@TODO: Warn here?
return true;
}
else
{
return false;
}
}
}
}