| | | 1 | | // ReSharper disable once CheckNamespace |
| | | 2 | | namespace Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | /// <summary>Small string checks. Stored-procedure parameter helpers live in the provider package (e.g. <c>SqlServerPara |
| | | 5 | | public static class Util |
| | | 6 | | { |
| | | 7 | | /// <summary>Checks that a string has text other than whitespace, <c>"null"</c> or <c>"undefined"</c>.</summary> |
| | | 8 | | /// <param name="val">The string.</param> |
| | | 9 | | /// <returns><see langword="true"/> when it has real text.</returns> |
| | 0 | 10 | | public static bool IsNotEmpty( this string? val ) => val.TrimValue() is not null; |
| | | 11 | | |
| | | 12 | | /// <summary>Checks that a value is a non-zero whole number.</summary> |
| | | 13 | | /// <param name="val">The value.</param> |
| | | 14 | | /// <returns><see langword="true"/> when it parses as a non-zero <see cref="int"/>.</returns> |
| | | 15 | | public static bool IsNotEmptyNumber( this object? val ) |
| | 0 | 16 | | => val?.ToString().TrimValue() is { } text && int.TryParse( text, NumberStyles.Integer, CultureInfo.InvariantCul |
| | | 17 | | |
| | | 18 | | /// <summary>Trims a string; whitespace, <c>"null"</c> and <c>"undefined"</c> become <see langword="null"/>.</summar |
| | | 19 | | /// <param name="val">The string.</param> |
| | | 20 | | /// <returns>The trimmed string, or <see langword="null"/>.</returns> |
| | | 21 | | public static string? TrimValue( this string? val ) |
| | | 22 | | { |
| | 0 | 23 | | if ( string.IsNullOrWhiteSpace( val ) ) { return null; } |
| | | 24 | | |
| | | 25 | | |
| | 0 | 26 | | var trimmed = val.Trim(); |
| | | 27 | | |
| | | 28 | | |
| | 0 | 29 | | return trimmed is "null" or "undefined" ? null : trimmed; |
| | | 30 | | } |
| | | 31 | | } |