diff --git a/SabreTools.Filter/FieldManipulator.cs b/SabreTools.Filter/FieldManipulator.cs index c02f2ab7..20d28609 100644 --- a/SabreTools.Filter/FieldManipulator.cs +++ b/SabreTools.Filter/FieldManipulator.cs @@ -36,15 +36,15 @@ namespace SabreTools.Filter public static bool RemoveField(DictionaryBase? dictionaryBase, string? fieldName) { // If the item or field name are missing, we can't do anything - if (dictionaryBase == null || string.IsNullOrWhiteSpace(fieldName)) + if (dictionaryBase == null || string.IsNullOrEmpty(fieldName)) return false; // If the key doesn't exist, then it's already removed - if (!dictionaryBase.ContainsKey(fieldName)) + if (!dictionaryBase.ContainsKey(fieldName!)) return true; // Remove the key - dictionaryBase.Remove(fieldName); + dictionaryBase.Remove(fieldName!); return true; } @@ -54,7 +54,7 @@ namespace SabreTools.Filter public static bool SetField(DictionaryBase? dictionaryBase, string? fieldName, object value) { // If the item or field name are missing, we can't do anything - if (dictionaryBase == null || string.IsNullOrWhiteSpace(fieldName)) + if (dictionaryBase == null || string.IsNullOrEmpty(fieldName)) return false; // Retrieve the list of valid fields for the item and validate @@ -63,7 +63,7 @@ namespace SabreTools.Filter return false; // Set the field with the new value - dictionaryBase[fieldName] = value; + dictionaryBase[fieldName!] = value; return true; } diff --git a/SabreTools.Filter/FilterObject.cs b/SabreTools.Filter/FilterObject.cs index d3faa905..359932a5 100644 --- a/SabreTools.Filter/FilterObject.cs +++ b/SabreTools.Filter/FilterObject.cs @@ -14,17 +14,29 @@ namespace SabreTools.Filter /// /// Key name for the filter /// +#if NETFRAMEWORK || NETCOREAPP3_1 + public string[] Key { get; private set; } +#else public string[] Key { get; init; } +#endif /// /// Value to match in the filter /// +#if NETFRAMEWORK || NETCOREAPP3_1 + public string? Value { get; private set; } +#else public string? Value { get; init; } +#endif /// /// Operation on how to match the filter /// +#if NETFRAMEWORK || NETCOREAPP3_1 + public Operation Operation { get; private set; } +#else public Operation Operation { get; init; } +#endif public FilterObject(string filterString) { @@ -322,11 +334,19 @@ namespace SabreTools.Filter return false; // If we find a special character, try parsing as regex +#if NETFRAMEWORK + if (value.Contains("^") + || value.Contains("$") + || value.Contains("*") + || value.Contains("?") + || value.Contains("+")) +#else if (value.Contains('^') || value.Contains('$') || value.Contains('*') || value.Contains('?') || value.Contains('+')) +#endif { try { @@ -348,10 +368,10 @@ namespace SabreTools.Filter private bool? ConvertToBoolean(string? value) { // If we don't have a valid string, we can't do anything - if (string.IsNullOrWhiteSpace(value)) + if (string.IsNullOrEmpty(value)) return null; - return value.ToLowerInvariant() switch + return value!.ToLowerInvariant() switch { "true" or "yes" => true, "false" or "no" => false, diff --git a/SabreTools.Filter/FilterParser.cs b/SabreTools.Filter/FilterParser.cs index 9c94562a..576aa624 100644 --- a/SabreTools.Filter/FilterParser.cs +++ b/SabreTools.Filter/FilterParser.cs @@ -12,7 +12,7 @@ namespace SabreTools.Filter public static (string?, string?) ParseFilterId(string itemFieldString) { // If we don't have a filter ID, we can't do anything - if (string.IsNullOrWhiteSpace(itemFieldString)) + if (string.IsNullOrEmpty(itemFieldString)) return (null, null); // If we only have one part, we can't do anything @@ -29,23 +29,23 @@ namespace SabreTools.Filter public static (string?, string?) ParseFilterId(string itemName, string? fieldName) { // If we don't have a filter ID, we can't do anything - if (string.IsNullOrWhiteSpace(itemName) || string.IsNullOrWhiteSpace(fieldName)) + if (string.IsNullOrEmpty(itemName) || string.IsNullOrEmpty(fieldName)) return (null, null); // Return santized values based on the split ID return itemName.ToLowerInvariant() switch { // Header - "header" => ParseHeaderFilterId(fieldName), + "header" => ParseHeaderFilterId(fieldName!), // Machine - "game" => ParseMachineFilterId(fieldName), - "machine" => ParseMachineFilterId(fieldName), - "resource" => ParseMachineFilterId(fieldName), - "set" => ParseMachineFilterId(fieldName), + "game" => ParseMachineFilterId(fieldName!), + "machine" => ParseMachineFilterId(fieldName!), + "resource" => ParseMachineFilterId(fieldName!), + "set" => ParseMachineFilterId(fieldName!), // DatItem - _ => ParseDatItemFilterId(itemName, fieldName), + _ => ParseDatItemFilterId(itemName, fieldName!), }; } diff --git a/SabreTools.Filter/FilterRunner.cs b/SabreTools.Filter/FilterRunner.cs index 06997ce6..37e023b3 100644 --- a/SabreTools.Filter/FilterRunner.cs +++ b/SabreTools.Filter/FilterRunner.cs @@ -12,7 +12,11 @@ namespace SabreTools.Filter /// /// Set of filters to be run against an object /// +#if NETFRAMEWORK || NETCOREAPP3_1 + public FilterObject[] Filters { get; private set; } +#else public FilterObject[] Filters { get; init; } +#endif public FilterRunner(FilterObject[]? filters) { @@ -35,7 +39,7 @@ namespace SabreTools.Filter this.Filters = filters.ToArray(); } - + /// /// Run filtering on a DictionaryBase item /// diff --git a/SabreTools.Filter/SabreTools.Filter.csproj b/SabreTools.Filter/SabreTools.Filter.csproj index efd05131..eee89a7e 100644 --- a/SabreTools.Filter/SabreTools.Filter.csproj +++ b/SabreTools.Filter/SabreTools.Filter.csproj @@ -1,10 +1,23 @@  - net6.0;net8.0 - latest - enable - true + + net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 + false + false + latest + enable + true + true + 1.1.2 + + + Matt Nadareski + Copyright (c)2016-2023 Matt Nadareski + https://github.com/SabreTools/ + https://github.com/SabreTools/SabreTools + git diff --git a/SabreTools.Filter/TypeHelper.cs b/SabreTools.Filter/TypeHelper.cs index 6b608d03..45d5418b 100644 --- a/SabreTools.Filter/TypeHelper.cs +++ b/SabreTools.Filter/TypeHelper.cs @@ -21,12 +21,18 @@ namespace SabreTools.Filter if (fields == null) return null; +#if NET20 || NET35 || NET40 + // TODO: Figure out how to do this, try using the following: + // https://learn.microsoft.com/en-us/dotnet/api/system.reflection.customattributedata?view=net-8.0 + return null; +#else return fields .Where(f => f.IsLiteral && !f.IsInitOnly) .Where(f => f.CustomAttributes.Any(a => a.AttributeType == typeof(NoFilterAttribute))) .Select(f => f.GetRawConstantValue() as string) .Where(v => v != null) .ToArray()!; +#endif } /// @@ -34,7 +40,7 @@ namespace SabreTools.Filter /// public static Type? GetDatItemType(string? itemType) { - if (string.IsNullOrWhiteSpace(itemType)) + if (string.IsNullOrEmpty(itemType)) return null; return AppDomain.CurrentDomain.GetAssemblies() @@ -51,7 +57,13 @@ namespace SabreTools.Filter if (type == null) return null; +#if NET20 || NET35 || NET40 + // TODO: Figure out how to do this, try using the following: + // https://learn.microsoft.com/en-us/dotnet/api/system.reflection.customattributedata?view=net-8.0 + return null; +#else return type.GetCustomAttribute()?.ElementName; +#endif } } }