mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add field replacement to manipulator (unused)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using SabreTools.Core;
|
||||||
using SabreTools.Models.Metadata;
|
using SabreTools.Models.Metadata;
|
||||||
|
|
||||||
namespace SabreTools.Filter
|
namespace SabreTools.Filter
|
||||||
@@ -54,6 +55,28 @@ namespace SabreTools.Filter
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replace a field from one DictionaryBase to another
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set a field in a given DictionaryBase
|
/// Set a field in a given DictionaryBase
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user