From 8c11eedbcd86dd042208fd8a469fbf10f19626d9 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 5 Mar 2024 19:26:03 -0500 Subject: [PATCH] Add field replacement to manipulator (unused) --- SabreTools.Filter/FieldManipulator.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/SabreTools.Filter/FieldManipulator.cs b/SabreTools.Filter/FieldManipulator.cs index 2562e283..4bec43f6 100644 --- a/SabreTools.Filter/FieldManipulator.cs +++ b/SabreTools.Filter/FieldManipulator.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Text.RegularExpressions; +using SabreTools.Core; using SabreTools.Models.Metadata; namespace SabreTools.Filter @@ -54,6 +55,28 @@ namespace SabreTools.Filter return true; } + /// + /// Replace a field from one DictionaryBase to another + /// + public static bool ReplaceField(DictionaryBase? from, DictionaryBase? to, string? fieldName) + { + // If the items or field name are missing, we can't do anything + if (from == null || to == null || string.IsNullOrEmpty(fieldName)) + return false; + + // If the types of the items are not the same, we can't do anything + if (from.GetType() != to.GetType()) + return false; + + // If the key doesn't exist in the source, we can't do anything + if (!from.ContainsKey(fieldName!)) + return false; + + // Set the key + to[fieldName!] = from[fieldName!]; + return true; + } + /// /// Set a field in a given DictionaryBase ///