mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-10-01 11:03:22 +00:00
Support .NET Framework 2.0
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.IO
|
||||
@@ -118,7 +120,7 @@ namespace SabreTools.IO
|
||||
return null;
|
||||
|
||||
// If it does and it is empty, return a blank enumerable
|
||||
#if NET35
|
||||
#if NET20 || NET35
|
||||
if (!Directory.GetFiles(root, "*", SearchOption.AllDirectories).Any())
|
||||
#else
|
||||
if (!Directory.EnumerateFileSystemEntries(root, "*", SearchOption.AllDirectories).Any())
|
||||
@@ -126,7 +128,7 @@ namespace SabreTools.IO
|
||||
return [];
|
||||
|
||||
// Otherwise, get the complete list
|
||||
#if NET35
|
||||
#if NET20 || NET35
|
||||
return Directory.GetDirectories(root, "*", SearchOption.AllDirectories)
|
||||
.Where(dir => !Directory.GetFiles(dir, "*", SearchOption.AllDirectories).Any())
|
||||
.ToList();
|
||||
|
||||
15
IniFile.cs
15
IniFile.cs
@@ -2,7 +2,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.IO.Writers;
|
||||
@@ -221,18 +223,9 @@ namespace SabreTools.IO
|
||||
|
||||
#region IDictionary Impelementations
|
||||
|
||||
#if NET35 || NET40 || NET452
|
||||
public ICollection<string> Keys => _keyValuePairs?.Keys?.ToArray() ?? new string[0];
|
||||
#else
|
||||
public ICollection<string> Keys => _keyValuePairs?.Keys?.ToArray() ?? Array.Empty<string>();
|
||||
#endif
|
||||
public ICollection<string> Keys => _keyValuePairs?.Keys?.ToArray() ?? [];
|
||||
|
||||
|
||||
#if NET35 || NET40 || NET452
|
||||
public ICollection<string?> Values => _keyValuePairs?.Values?.ToArray() ?? new string[0];
|
||||
#else
|
||||
public ICollection<string?> Values => _keyValuePairs?.Values?.ToArray() ?? Array.Empty<string?>();
|
||||
#endif
|
||||
public ICollection<string?> Values => _keyValuePairs?.Values?.ToArray() ?? [];
|
||||
|
||||
public int Count => (_keyValuePairs as ICollection<KeyValuePair<string, string>>)?.Count ?? 0;
|
||||
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text.RegularExpressions;
|
||||
using SabreTools.IO;
|
||||
|
||||
/// TODO: Make this namespace a separate library
|
||||
namespace NaturalSort
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text.RegularExpressions;
|
||||
using SabreTools.IO;
|
||||
|
||||
/// TODO: Make this namespace a separate library
|
||||
namespace NaturalSort
|
||||
|
||||
110
OldDotNet.cs
110
OldDotNet.cs
@@ -1,7 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
#if NET35 || NET40
|
||||
#if NET20
|
||||
|
||||
namespace SabreTools.IO
|
||||
{
|
||||
internal static partial class EnumerationExtensions
|
||||
{
|
||||
internal delegate U LinqSelectDelegate<T, U>(T str);
|
||||
|
||||
internal delegate bool LinqWhereDelegate<T>(T str);
|
||||
|
||||
public static bool Any<T>(this IEnumerable<T> arr)
|
||||
{
|
||||
return arr.Count() != 0;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> Cast<T>(this MatchCollection arr)
|
||||
{
|
||||
foreach (var val in arr)
|
||||
{
|
||||
if (val is not T castVal)
|
||||
throw new System.ArrayTypeMismatchException();
|
||||
|
||||
yield return castVal;
|
||||
}
|
||||
}
|
||||
|
||||
public static int Count<T>(this IEnumerable<T> arr)
|
||||
{
|
||||
int counter = 0;
|
||||
foreach (var val in arr)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
public static IEnumerable<U> Select<T, U>(this IEnumerable<T> arr, LinqSelectDelegate<T, U> func)
|
||||
{
|
||||
foreach (var val in arr)
|
||||
{
|
||||
yield return func(val);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SequenceEqual<T>(this IEnumerable<T> arr1, IEnumerable<T> arr2)
|
||||
{
|
||||
if (arr1 == null || arr2 == null)
|
||||
return false;
|
||||
|
||||
if (arr1.Count() != arr2.Count())
|
||||
return false;
|
||||
|
||||
var arr1Array = arr1.ToArray();
|
||||
var arr2Array = arr2.ToArray();
|
||||
|
||||
for (int i = 0; i < arr1Array.Length; i++)
|
||||
{
|
||||
if (!arr1Array[i]?.Equals(arr2Array[i]) != true)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> Skip<T>(this IEnumerable<T> arr, int skip)
|
||||
{
|
||||
int counter = 0;
|
||||
foreach (var val in arr)
|
||||
{
|
||||
if (counter++ < skip)
|
||||
continue;
|
||||
|
||||
yield return val;
|
||||
}
|
||||
}
|
||||
|
||||
public static T[] ToArray<T>(this IEnumerable<T> arr)
|
||||
{
|
||||
return [.. arr];
|
||||
}
|
||||
|
||||
public static List<T> ToList<T>(this IEnumerable<T> arr)
|
||||
{
|
||||
return [.. arr];
|
||||
}
|
||||
public static IEnumerable<T> Where<T>(this T[] arr, LinqWhereDelegate<T> func)
|
||||
{
|
||||
foreach (var val in arr)
|
||||
{
|
||||
if (func(val))
|
||||
yield return val;
|
||||
}
|
||||
}
|
||||
public static IEnumerable<T> Where<T>(this IEnumerable<T> arr, LinqWhereDelegate<T> func)
|
||||
{
|
||||
foreach (var val in arr)
|
||||
{
|
||||
if (func(val))
|
||||
yield return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
|
||||
namespace SabreTools.IO
|
||||
{
|
||||
|
||||
14
PathTool.cs
14
PathTool.cs
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using NaturalSort;
|
||||
|
||||
namespace SabreTools.IO
|
||||
@@ -71,8 +73,8 @@ namespace SabreTools.IO
|
||||
private static List<string> GetDirectoriesOrderedHelper(string dir, List<string> infiles, string pattern)
|
||||
{
|
||||
// Take care of the files in the top directory
|
||||
#if NET35
|
||||
List<string> toadd = Directory.GetDirectories(dir, pattern, SearchOption.TopDirectoryOnly).ToList();
|
||||
#if NET20 || NET35
|
||||
List<string> toadd = [.. Directory.GetDirectories(dir, pattern, SearchOption.TopDirectoryOnly)];
|
||||
#else
|
||||
List<string> toadd = Directory.EnumerateDirectories(dir, pattern, SearchOption.TopDirectoryOnly).ToList();
|
||||
#endif
|
||||
@@ -154,8 +156,8 @@ namespace SabreTools.IO
|
||||
private static List<string> GetFilesOrderedHelper(string dir, List<string> infiles, string pattern)
|
||||
{
|
||||
// Take care of the files in the top directory
|
||||
#if NET35
|
||||
List<string> toadd = Directory.GetFiles(dir, pattern, SearchOption.TopDirectoryOnly).ToList();
|
||||
#if NET20 || NET35
|
||||
List<string> toadd = [.. Directory.GetFiles(dir, pattern, SearchOption.TopDirectoryOnly)];
|
||||
#else
|
||||
List<string> toadd = Directory.EnumerateFiles(dir, pattern, SearchOption.TopDirectoryOnly).ToList();
|
||||
#endif
|
||||
@@ -163,8 +165,8 @@ namespace SabreTools.IO
|
||||
infiles.AddRange(toadd);
|
||||
|
||||
// Then recurse through and add from the directories
|
||||
#if NET35
|
||||
List<string> subDirs = Directory.GetDirectories(dir, pattern, SearchOption.TopDirectoryOnly).ToList();
|
||||
#if NET20 || NET35
|
||||
List<string> subDirs = [.. Directory.GetDirectories(dir, pattern, SearchOption.TopDirectoryOnly)];
|
||||
#else
|
||||
List<string> subDirs = Directory.EnumerateDirectories(dir, pattern, SearchOption.TopDirectoryOnly).ToList();
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.IO.Readers
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -124,7 +126,7 @@ namespace SabreTools.IO.Readers
|
||||
// https://stackoverflow.com/questions/3776458/split-a-comma-separated-string-with-both-quoted-and-unquoted-strings
|
||||
var lineSplitRegex = new Regex($"(?:^|{Separator})(\"(?:[^\"]+|\"\")*\"|[^{Separator}]*)");
|
||||
var temp = new List<string>();
|
||||
foreach (Match? match in lineSplitRegex.Matches(fullLine))
|
||||
foreach (Match? match in lineSplitRegex.Matches(fullLine).Cast<Match?>())
|
||||
{
|
||||
string? curr = match?.Value;
|
||||
if (curr == null)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
@@ -25,4 +25,9 @@
|
||||
<None Include="README.md" Pack="true" PackagePath=""/>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Support for old .NET versions -->
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`))">
|
||||
<PackageReference Include="Hafner.Compatibility.ExtensionAttribute" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.IO
|
||||
|
||||
Reference in New Issue
Block a user