Skip to content

Commit 9b44ae4

Browse files
authored
v1.1
### Features * Added helper text for classes and methods.
1 parent 937b5ff commit 9b44ae4

File tree

7 files changed

+60
-8
lines changed

7 files changed

+60
-8
lines changed

.github/workflows/dotnet.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jobs:
2121
- name: Restore dependencies
2222
run: dotnet restore Source/ArgumentAssert/ArgumentAssert.csproj
2323
- name: Build
24-
run: dotnet build --no-restore Source/ArgumentAssert/ArgumentAssert.csproj
24+
run: dotnet build --no-restore --configuration Release Source/ArgumentAssert/ArgumentAssert.csproj
25+
- name: Pack
26+
run: dotnet pack --no-build --configuration Release --include-symbols -p:SymbolPackageFormat=snupkg -o . Source/ArgumentAssert/ArgumentAssert.csproj
2527

2628
# Build Samples
2729
- name: Build Assert Value Is In Range Sample
@@ -32,7 +34,4 @@ jobs:
3234
# Publish ArgumentAssert
3335
- name: Publish
3436
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
35-
uses: brandedoutcast/[email protected]
36-
with:
37-
PROJECT_FILE_PATH: Source/ArgumentAssert/ArgumentAssert.csproj
38-
NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
37+
run: dotnet nuget push *.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate

ReadMe.md

+13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ When the assertion fails, the exception message shows the failed expression.
3939
Unhandled exception. System.ArgumentAssertException: value is { Length: > 0 and < 10 }
4040
```
4141

42+
## Sample: Streamline calls to Assert()
43+
44+
The following code uses the `using static` statement to expose the `Assert()` method without requiring the class name. This approach streamlines the code when many assertions are being performed throughout the codebase.
45+
```csharp
46+
using static System.ArgumentAssertException;
47+
48+
int AssertValueIsInRange(int value) {
49+
Assert(value is > 0 and < 10);
50+
return value;
51+
}
52+
```
53+
54+
4255
## License
4356

4457
Licensed under the Apache License, Version 2.0 (the "License");

ReleaseNotes.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Release Notes
22

3+
## v1.1 (2023-08-20)
4+
5+
### Features
6+
7+
* Added helper text for classes and methods.
8+
9+
### Samples
10+
11+
* Added `AssertGlobal` sample to show how to use `using static` to simplify calls to `Assert()` method.
12+
313
## v1.0 (2022-02-14)
414

515
### Features
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="../../Source/ArgumentAssert/ArgumentAssert.csproj"/>
10+
</ItemGroup>
11+
</Project>

Samples/AssertGlobal/Program.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using static System.ArgumentAssertException;
2+
3+
AssertValueIsInRange(10);
4+
5+
int AssertValueIsInRange(int value) {
6+
Assert(value is > 0 and < 10);
7+
return value;
8+
}

Source/ArgumentAssert/ArgumentAssert.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<Nullable>enable</Nullable>
66

77
<PackageId>ArgumentAssert</PackageId>
8-
<Version>1.0</Version>
8+
<Version>1.1</Version>
99
<Title>Argument Assertion Library</Title>
1010
<Description>Assert argument values and throw descriptive exceptions</Description>
11-
<Copyright>Copyright (C) 2022</Copyright>
11+
<Copyright>Copyright (C) 2022-2023</Copyright>
1212
<Authors>Bjorg</Authors>
1313

1414
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

Source/ArgumentAssert/ArgumentAssertException.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,21 @@ namespace System;
1919
using System.Diagnostics.CodeAnalysis;
2020
using System.Runtime.CompilerServices;
2121

22+
/// <summary>
23+
/// The <see cref="ArgumentAssertException"/> class represents an exception that is
24+
/// thrown when an assertion fails.
25+
/// </summary>
2226
public class ArgumentAssertException : ArgumentException {
2327

2428
//--- Class Methods ---
29+
30+
/// <summary>
31+
/// This method throws a <see cref="ArgumentAssertException"/> exception when the expression evaluates to false.
32+
/// The method is annotated to inform code analysis about that the assertions of the expression are true when no
33+
/// exception is thrown.
34+
/// </summary>
35+
/// <param name="expression">Expression to assert on</param>
36+
/// <param name="expressionText">(optional) Text for exception message. The string equivalent of the expression is used when omitted.</param>
2537
public static void Assert(
2638
[DoesNotReturnIf(false)] bool expression,
2739
[CallerArgumentExpression("expression")] string? expressionText = default
@@ -38,4 +50,3 @@ public static void Assert(
3850
public ArgumentAssertException() { }
3951
public ArgumentAssertException(string? message) : base(message) { }
4052
}
41-

0 commit comments

Comments
 (0)