Initial implementation

This commit is contained in:
Simon Gruber
2023-08-10 09:04:36 +02:00
commit 4c4ed48e38
95 changed files with 4142 additions and 0 deletions
@@ -0,0 +1,41 @@
using System.Text.RegularExpressions;
namespace Common.Extensions;
/// <summary>
/// Extensions for the string object type
/// </summary>
public static class StringExtensions
{
private static readonly Regex patternRegex = new Regex(@"^\*$");
/// <summary>
/// Determines whether this string contains the specified string. Not case sensitive.
/// </summary>
/// <param name="source"> The source.</param>
/// <param name="contained">The contained.</param>
public static bool ContainsIgnoreCase(this string source, string contained)
{
return source?.IndexOf(contained, StringComparison.InvariantCultureIgnoreCase) >= 0;
}
/// <summary>
/// Expands a path containing a wildcard pattern
/// </summary>
/// <param name="self"></param>
/// <returns></returns>
public static ICollection<string> ExpandPath(this string self)
{
string pattern = Path.GetFileName(self);
if (patternRegex.IsMatch(pattern))
{
return Directory.GetFiles(
self.Substring(0, self.Length - pattern.Length),
pattern,
SearchOption.TopDirectoryOnly
);
}
return new[] { self };
}
}