Skip to content

Commit

Permalink
TrowIfNullOrEmpty
Browse files Browse the repository at this point in the history
TrowIfNullOrEmpty
  • Loading branch information
DomCR committed Apr 29, 2024
1 parent 6203993 commit 4d29042
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions CSUtilities.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using CSUtilities.Extensions;
using Xunit;

namespace CSUtilities.Tests.Extensions
{
public class StringExtensionsTests
{
[Fact]
public void IsNullOrEmptyTest()
{
string n = null;
Assert.True(n.IsNullOrEmpty());
}
}
}
10 changes: 9 additions & 1 deletion CSUtilities/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

namespace CSUtilities.Extensions
{
//TODO: refactor extensions
/// <summary>
/// String utility extensions.
/// </summary>
Expand All @@ -25,6 +25,14 @@ public static bool IsNullOrWhiteSpace(this string str)
return string.IsNullOrWhiteSpace(str);
}

public static void TrowIfNullOrEmpty(this string str, [CallerMemberName] string name = null)
{
if (string.IsNullOrEmpty(str))
{
throw new ArgumentException("", name);
}
}

/// <summary>
/// Return an array with all the lines.
/// </summary>
Expand Down

0 comments on commit 4d29042

Please sign in to comment.