You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://youtu.be/wTDY_Gt46vU)
11
-
12
10
## Light.GuardClauses - easy precondition checks in C# / .NET
13
11
14
12
[Read the full docs in the Wiki](https://github.com/feO2x/Light.GuardClauses/wiki)
@@ -39,11 +37,13 @@ public class Foo
39
37
40
38
publicFoo(IBar? bar)
41
39
{
42
-
_bar=bar.MustNotBeNull(nameof(bar));
40
+
_bar=bar.MustNotBeNull();
43
41
}
44
42
}
45
43
```
46
44
45
+
> As of version 10, Light.GuardClauses supports the [CallerArgumentExpressionAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callerargumentexpressionattribute) of C# 10. If your C# compiler is on a lower version, then the `CallerArgumentExpressionAttribute` might not be respected - you should then call all assertions with an explicit parameter name, e.g. `bar.MustNotBeNull(nameof(bar))`. You can use the C# 10 compiler by e.g. installing .NET 6 and/or Visual Studio 2022. The `CallerArgumentExpressionAttribute` is backwards-compatible, so it can be used with projects targeting .NET Standard 2, .NET Framework, or .NET Core.
46
+
47
47
By using **Light.GuardClauses**, you'll gain access to assertions for a vast amount of scenarios like checking strings, collections, enums, URIs, `DateTime`, `Type`, `IComparable<T>`, `IEnumerable`, `IEnumerable<T>`, and `Span<T>`. Just have a look at these examples:
@@ -92,7 +92,7 @@ Every assertion is well-documented - explore them using IntelliSense or check ou
92
92
93
93
## Light.GuardClauses is optimized
94
94
95
-
Since version 4.x, **Light.GuardClauses** is optimized for performance (measured in .NET 4.8 and .NET Core 3.x). With the incredible help of [@redknightlois](https://github.com/redknightlois) and the awesome tool [Benchmark.NET](https://github.com/dotnet/BenchmarkDotNet), most assertions are as fast as your imperative code would be.
95
+
Since version 4.x, **Light.GuardClauses** is optimized for performance (measured in .NET 4.8 and .NET 6). With the incredible help of [@redknightlois](https://github.com/redknightlois) and the awesome tool [Benchmark.NET](https://github.com/dotnet/BenchmarkDotNet), most assertions are as fast as your imperative code would be.
96
96
97
97
**Light.GuardClauses** has support for [.NET analyzers / FxCopAnalyzers](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview) with the `ValidatedNotNullAttribute`. Analyzers will know when an assertion validated that a parameters is not null and consequently, CA1062 will not be raised.
98
98
@@ -104,17 +104,15 @@ And, of course, the functional correctness of **Light.GuardClauses** is covered
104
104
105
105
## Supported Platforms
106
106
107
-
**Light.GuardClauses** supports the following platforms:
108
-
- .NET Standard 2.0 or higher
109
-
- .NET Core 3.0 or higher
107
+
**Light.GuardClauses** is built against [.NET Standard 2.0 and 2.1](https://docs.microsoft.com/en-us/dotnet/standard/net-standard), thus it can be used in frameworks like .NET 6, .NET Core 3.1, .NET Framework 4.6.1 or newer, Unity, Mono, or UWP.
110
108
111
109
## How to Install
112
110
113
111
Light.GuardClauses is available as a [NuGet package](https://www.nuget.org/packages/Light.GuardClauses/).
-**Visual Studio Package Manager Console**: `Install-Package Light.GuardClauses`
117
-
-**Package Reference in csproj**: `<PackageReference Include="Light.GuardClauses" Version="9.0.0" />`
115
+
-**Package Reference in csproj**: `<PackageReference Include="Light.GuardClauses" Version="10.0.0" />`
118
116
119
117
Also, you can incorporate Light.GuardClauses as a **single source file** where the API is changed to `internal`. This is especially interesting for framework / library developers that do not want to have a dependency on the Light.GuardClauses DLL. You can grab the default .NET Standard 2.0 version in [Light.GuardClauses.SingleFile.cs](https://github.com/feO2x/Light.GuardClauses/blob/master/Light.GuardClauses.SingleFile.cs) or you can use the [Light.GuardClauses.SourceCodeTransformation](https://github.com/feO2x/Light.GuardClauses/tree/master/Code/Light.GuardClauses.SourceCodeTransformation) project to create your custom file. You can learn more about it [here](https://github.com/feO2x/Light.GuardClauses/wiki/Including-Light.GuardClauses-as-source-code).
0 commit comments