Smartstore.BTCPayServer/tools/Smartstore.WebApi.Client/Extensions/StringExtensions.cs
2022-10-04 16:21:18 +02:00

67 lines
2.2 KiB
C#

using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace Smartstore.WebApi.Client
{
internal static class StringExtensions
{
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Dump(this string value, bool appendMarks = false)
{
Debug.WriteLine(value);
Debug.WriteLineIf(appendMarks, "------------------------------------------------");
}
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ToInt(this string value, int defaultValue = 0)
{
return int.TryParse(value, out int result) ? result : defaultValue;
}
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string EmptyNull(this string value)
{
return (value ?? string.Empty).Trim();
}
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NullEmpty(this string value)
{
return string.IsNullOrEmpty(value) ? null : value;
}
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsEmpty(this string value)
{
return string.IsNullOrWhiteSpace(value);
}
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool HasValue(this string value)
{
return !string.IsNullOrWhiteSpace(value);
}
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string FormatInvariant(this string format, params object[] objects)
{
return string.Format(CultureInfo.InvariantCulture, format, objects);
}
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EqualsNoCase(this string value, string other)
{
return string.Compare(value, other, StringComparison.OrdinalIgnoreCase) == 0;
}
}
}