Skip to content

Commit

Permalink
Add John.CallerArgumentExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
john72831 committed Mar 12, 2023
1 parent 1ffc39e commit 812a9f5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions John.CallerArgumentExpression/EnsureThat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace John.CallerArgumentExpression;

public static class EnsureThat
{
public static void ItIsNotEmpty<T>(IEnumerable<T> value, [CallerArgumentExpression("value")] string message = "")
{
if(!value .Any())
{
throw new ArgumentException("Enumerable is empty", message);
}
}
}
10 changes: 10 additions & 0 deletions John.CallerArgumentExpression/John.CallerArgumentExpression.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions John.CallerArgumentExpression/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using John.CallerArgumentExpression;

var array = new int[0];

EnsureThat.ItIsNotEmpty(array);
7 changes: 7 additions & 0 deletions John.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "John.Api.MinimalApi", "John
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "John.WireMock.TestTarge", "John.WireMock.TestTarge\John.WireMock.TestTarge.csproj", "{1B33D7D8-DBE2-4E4C-8B70-74223C9F5ABF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "John.CallerArgumentExpression", "John.CallerArgumentExpression\John.CallerArgumentExpression.csproj", "{A9F02D41-09E8-4862-9AA1-D6821D6C7AF7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -165,6 +167,10 @@ Global
{1B33D7D8-DBE2-4E4C-8B70-74223C9F5ABF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B33D7D8-DBE2-4E4C-8B70-74223C9F5ABF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B33D7D8-DBE2-4E4C-8B70-74223C9F5ABF}.Release|Any CPU.Build.0 = Release|Any CPU
{A9F02D41-09E8-4862-9AA1-D6821D6C7AF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9F02D41-09E8-4862-9AA1-D6821D6C7AF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9F02D41-09E8-4862-9AA1-D6821D6C7AF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9F02D41-09E8-4862-9AA1-D6821D6C7AF7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -196,6 +202,7 @@ Global
{653E11B0-AF47-439E-9B67-C1C367671943} = {DFB9EC58-DEA0-4C7C-A44A-404A091792EA}
{AFFB870E-BF24-457F-8EB4-6120464AFA1B} = {A9756AC7-5794-4122-8CD4-EA27917AC914}
{1B33D7D8-DBE2-4E4C-8B70-74223C9F5ABF} = {DFB9EC58-DEA0-4C7C-A44A-404A091792EA}
{A9F02D41-09E8-4862-9AA1-D6821D6C7AF7} = {A9756AC7-5794-4122-8CD4-EA27917AC914}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4A169F98-AF3D-41C2-86AA-956352BF2D93}
Expand Down

0 comments on commit 812a9f5

Please sign in to comment.