Files
SabreTools.IO/SabreTools.IO.Extensions/StringExtensions.cs
Matt Nadareski d614379cf5 Libraries
This change looks dramatic, but it's just separating out the already-split namespaces into separate top-level folders. In theory, every single one could be built into their own Nuget package. `SabreTools.IO.Meta` builds the normal Nuget package that is used by all other projects and includes all namespaces. `SabreTools.IO` builds to `SabreTools.IO.Common` to avoid overwriting issues on publish.
2026-03-21 13:55:42 -04:00

68 lines
2.3 KiB
C#

using System;
namespace SabreTools.IO.Extensions
{
public static class StringExtensions
{
#region Optional Extensions
/// <inheritdoc cref="string.Contains(string)"/>
public static bool OptionalContains(this string? self, string value)
=> OptionalContains(self, value, StringComparison.Ordinal);
/// <inheritdoc cref="string.Contains(string, StringComparison)"/>
public static bool OptionalContains(this string? self, string value, StringComparison comparisonType)
{
if (self is null)
return false;
#if NETFRAMEWORK || NETSTANDARD2_0
return self.Contains(value);
#else
return self.Contains(value, comparisonType);
#endif
}
/// <inheritdoc cref="string.EndsWith(string)"/>
public static bool OptionalEndsWith(this string? self, string value)
=> OptionalEndsWith(self, value, StringComparison.Ordinal);
/// <inheritdoc cref="string.EndsWith(string, StringComparison)"/>
public static bool OptionalEndsWith(this string? self, string value, StringComparison comparisonType)
{
if (self is null)
return false;
return self.EndsWith(value, comparisonType);
}
/// <inheritdoc cref="string.Equals(string)"/>
public static bool OptionalEquals(this string? self, string value)
=> OptionalEquals(self, value, StringComparison.Ordinal);
/// <inheritdoc cref="string.Equals(string, StringComparison)"/>
public static bool OptionalEquals(this string? self, string value, StringComparison comparisonType)
{
if (self is null)
return false;
return self.Equals(value, comparisonType);
}
/// <inheritdoc cref="string.StartsWith(string)"/>
public static bool OptionalStartsWith(this string? self, string value)
=> OptionalStartsWith(self, value, StringComparison.Ordinal);
/// <inheritdoc cref="string.StartsWith(string, StringComparison)"/>
public static bool OptionalStartsWith(this string? self, string value, StringComparison comparisonType)
{
if (self is null)
return false;
return self.StartsWith(value, comparisonType);
}
#endregion
}
}