-
Notifications
You must be signed in to change notification settings - Fork 4
/
StringExtensions.cs
61 lines (51 loc) · 1.98 KB
/
StringExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
namespace Menees
{
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text;
#endregion
/// <summary>
/// Adds extension methods to <see cref="string"/>.
/// </summary>
/// <remarks>
/// These methods are properly annotated for nullable analysis, unlike string.IsNullOrEmpty in netstandard2.0 and net48 builds.
/// </remarks>
public static class StringExtensions
{
#region Public Methods
/// <summary>
/// Shortcut for <see cref="string.IsNullOrWhiteSpace"/>. Blank means "null, empty, or whitespace".
/// </summary>
[Obsolete("Use IsWhiteSpace() instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
public static bool IsBlank([NotNullWhen(false)] this string? text) => text.IsWhiteSpace();
/// <summary>
/// Shortcut for NOT <see cref="string.IsNullOrWhiteSpace"/>. Blank means "null, empty, or whitespace".
/// </summary>
[Obsolete("Use IsNotWhiteSpace() instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
public static bool IsNotBlank([NotNullWhen(true)] this string? text) => text.IsNotWhiteSpace();
/// <summary>
/// Shortcut for <see cref="string.IsNullOrEmpty"/>.
/// </summary>
public static bool IsEmpty([NotNullWhen(false)] this string? text) => string.IsNullOrEmpty(text);
/// <summary>
/// Shortcut for NOT <see cref="string.IsNullOrEmpty"/>.
/// </summary>
public static bool IsNotEmpty([NotNullWhen(true)] this string? text) => !string.IsNullOrEmpty(text);
/// <summary>
/// Shortcut for <see cref="string.IsNullOrWhiteSpace"/>.
/// </summary>
public static bool IsWhiteSpace([NotNullWhen(false)] this string? text) => string.IsNullOrWhiteSpace(text);
/// <summary>
/// Shortcut for NOT <see cref="string.IsNullOrWhiteSpace"/>.
/// </summary>
public static bool IsNotWhiteSpace([NotNullWhen(true)] this string? text) => !string.IsNullOrWhiteSpace(text);
#endregion
}
}