Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
f484c96
feat: update single-source file for v12.0
feO2x Oct 27, 2024
eb8f828
refactor: move MustNotBeNull into own file
feO2x Nov 28, 2024
f4d034e
refactor: move MustNotBeDefault into own file
feO2x Nov 28, 2024
a36e674
refactor: move MustNotBeNullReference into own file
feO2x Nov 28, 2024
27f770d
refactor: move MustBeOfType method to its own file
feO2x Dec 10, 2024
61b7e37
refactor: move IsEmpty and MustNotBeEmpty from CommonAssertions to ow…
feO2x Dec 11, 2024
04769a1
refactor: move IsValidEnumValue and MustBeValidEnumValue from CommonA…
feO2x Dec 11, 2024
90969ce
refactor: move InvalidOperation from CommonAssertions into own file
feO2x Dec 11, 2024
4b39725
refactor: move InvalidArgument from CommonAssertions to own file
feO2x Dec 11, 2024
95df065
refactor: move InvalidState from CommonAssertions into own file
feO2x Dec 11, 2024
047c85a
refactor: move MustHaveValue from CommonAssertions into own file
feO2x Dec 11, 2024
375e8a8
refactor: move IsSameAs from CommonAssertions into own file
feO2x Dec 11, 2024
3a6bc25
refactor: move MustNotBeSameAs from CommonAssertions to own file
feO2x Dec 11, 2024
ad1e3b2
refactor: move MustBe from CommonAssertions to own file
feO2x Dec 11, 2024
99421ca
refactor: move MustNotBe from CommonAssertions into own file
feO2x Dec 11, 2024
49fb37a
refactor: move IsApproximately from CommonAssertions into own file
feO2x Dec 11, 2024
f2cb77c
refactor: move IsGreaterThanOrApproximately into own file
feO2x Dec 11, 2024
6275fd0
refactor: move IsLessThanOrApproximately to own file
feO2x Dec 11, 2024
c048a7b
refactor: rename file Check.CommonAssertions.cs to Check.cs
feO2x Dec 11, 2024
d757ec4
chore: update ReSharper settings for new style guide
feO2x Dec 11, 2024
87ed851
code style: apply new style to some files
feO2x Dec 11, 2024
12ef6a6
chore: update Light.GuardClauses.AllProjects.sln.DotSettings for new …
feO2x Dec 11, 2024
40896c3
refactor: move all assertions of Check.ComparableAssertions.cs into o…
feO2x Dec 12, 2024
95706b5
refactor: move assertions from Check.UriAssertions.cs into their own …
feO2x Dec 12, 2024
dcc709d
refactor: move assertions from Check.TypeAssertions.cs into their own…
feO2x Dec 26, 2024
47efaf2
refactor: move assertions from Check.DateTimeAssertions.cs into their…
feO2x Dec 26, 2024
ff19ecd
refactor: move MustHaveCount assertions from Check.EnumerableAssertio…
feO2x Dec 26, 2024
329c0c4
refactor: move IsNullOrEmpty method from Check.EnumerableAssertions.c…
feO2x Dec 26, 2024
21ec6fb
refactor: move MustNotBeNullOrEmpty assertions from Check.EnumerableA…
feO2x Dec 26, 2024
795a8c4
refactor: move MustContain assertions from Check.EnumerableAssertions…
feO2x Dec 26, 2024
8beaeb2
refactor: move MustNotContain assertions from Check.EnumerableAsserti…
feO2x Dec 26, 2024
54c6279
refactor: move IsOneOf method from Check.EnumerableAssertions.cs to C…
feO2x Dec 26, 2024
26a101e
refactor: move MustBeOneOf assertions from Check.EnumerableAssertions…
feO2x Dec 26, 2024
dec6d48
refactor: move MustNotBeOneOf assertions from Check.EnumerableAsserti…
feO2x Dec 26, 2024
d0006fd
refactor: move MustHaveMinimumCount assertions from Check.EnumerableA…
feO2x Dec 26, 2024
3fb5c3f
refactor: move MustHaveMaximumCount assertions from Check.EnumerableA…
feO2x Dec 26, 2024
d73646e
refactor: move MustHaveLength assertions from Check.EnumerableAsserti…
feO2x Dec 26, 2024
6458bb4
refactor: move MustBeLongerThan assertions from Check.EnumerableAsser…
feO2x Dec 27, 2024
65fed4d
refactor: move MustBeLongerThanOrEqualTo assertions from Check.Enumer…
feO2x Dec 27, 2024
c484ccc
refactor: move MustBeShorterThan assertions from Check.EnumerableAsse…
feO2x Dec 27, 2024
5e4896f
refactor: rename Check.EnumerableAssertions.cs to Check.MustBeShorter…
feO2x Dec 28, 2024
7dcdf69
chore: update DotSettings files to include new user dictionary entry
feO2x Dec 28, 2024
90fed4a
refactor: move IsNullOrEmpty string check from Check.StringAssertions…
feO2x Dec 28, 2024
5a350bd
refactor: move MustNotBeNullOrEmpty string checks from Check.StringAs…
feO2x Dec 28, 2024
e199196
refactor: move IsNullOrWhiteSpace check from Check.StringAssertions.c…
feO2x Dec 28, 2024
70a2d82
refactor: move MustNotBeNullOrWhiteSpace checks from Check.StringAsse…
feO2x Dec 28, 2024
05423fb
refactor: move IsWhiteSpace check from Check.StringAssertions.cs to C…
feO2x Dec 28, 2024
8122950
refactor: move IsLetter check from Check.StringAssertions.cs to Check…
feO2x Dec 28, 2024
3f25229
refactor: move IsLetterOrDigit check from Check.StringAssertions.cs t…
feO2x Dec 28, 2024
008edac
refactor: move IsDigit check from Check.StringAssertions.cs to Check.…
feO2x Dec 28, 2024
79cb342
refactor: move MustBe string comparison methods from Check.StringAsse…
feO2x Dec 28, 2024
7a91a3e
refactor: move MustNotBe string comparison methods from Check.StringA…
feO2x Dec 28, 2024
9c14139
refactor: move MustMatch string validation methods from Check.StringA…
feO2x Dec 28, 2024
830ad72
refactor: move Equals string comparison method from Check.StringAsser…
feO2x Dec 28, 2024
b29102d
refactor: move MustContain string validation methods from Check.Strin…
feO2x Dec 28, 2024
cec7c6b
refactor: move MustNotContain string validation methods from Check.St…
feO2x Dec 28, 2024
3c20c86
refactor: move Contains string validation method from Check.StringAss…
feO2x Dec 28, 2024
c0d39a7
refactor: move IsSubstringOf string validation methods from Check.Str…
feO2x Dec 28, 2024
f4df5ff
refactor: move MustBeSubstringOf string validation methods from Check…
feO2x Dec 28, 2024
c7910bc
refactor: remove MustNotBeSubstringOf string validation methods from …
feO2x Dec 28, 2024
b5f24a3
refactor: move MustStartWith string validation methods from Check.Str…
feO2x Dec 28, 2024
9b474ed
refactor: add MustNotStartWith string validation methods and remove f…
feO2x Dec 28, 2024
40192d2
refactor: add MustEndWith string validation methods and remove from C…
feO2x Dec 28, 2024
8f6fef3
refactor: add MustNotEndWith string validation methods and remove fro…
feO2x Dec 28, 2024
c1a34cf
refactor: add IsEmailAddress validation methods and remove from Check…
feO2x Dec 28, 2024
8a9b839
refactor: move MustBeEmailAddress from Check.StringAssertions.cs to C…
feO2x Dec 28, 2024
7bc8934
refactor: move MustBeShorterThan methods from Check.StringAssertions.…
feO2x Dec 28, 2024
55b4a6b
refactor: move MustBeShorterThanOrEqualTo methods from Check.StringAs…
feO2x Dec 28, 2024
756ce0a
refactor: move MustHaveLength methods from Check.StringAssertions.cs …
feO2x Dec 28, 2024
2517eb2
refactor: move MustBeLongerThan methods from Check.StringAssertions.c…
feO2x Dec 28, 2024
9348950
refactor: move MustBeLongerThanOrEqualTo methods from Check.StringAss…
feO2x Dec 28, 2024
6f61a7e
refactor: move MustHaveLengthIn methods from Check.StringAssertions.c…
feO2x Dec 28, 2024
deeac5c
refactor: move IsNewLine method from Check.StringAssertions.cs to Che…
feO2x Dec 28, 2024
66a0de9
refactor: move MustBeNewLine methods from Check.StringAssertions.cs t…
feO2x Dec 28, 2024
e2c8e50
refactor: move IsTrimmed methods from Check.StringAssertions.cs to Ch…
feO2x Dec 28, 2024
59bb8d2
refactor: move MustBeTrimmed methods from Check.StringAssertions.cs t…
feO2x Dec 28, 2024
2a76442
refactor: move IsTrimmedAtStart methods from Check.StringAssertions.c…
feO2x Dec 28, 2024
9382b25
refactor: move MustBeTrimmedAtStart methods from Check.StringAssertio…
feO2x Dec 28, 2024
15f4869
refactor: move IsTrimmedAtEnd methods from Check.StringAssertions.cs …
feO2x Dec 28, 2024
41b2f2a
refactor: rename Check.StringAssertions.cs to Check.MustBeTrimmedAtEn…
feO2x Dec 28, 2024
e357f99
chore: reformat framework extensions and other files in main namespace
feO2x Dec 28, 2024
06c41e2
Merge pull request #103 from feO2x/smaller-files-refactoring
feO2x Dec 28, 2024
0f52dd5
fix: update copyright year in LICENSE file
feO2x Dec 28, 2024
67de246
feat: add IsEmptyOrWhiteSpace for Span<T>
feO2x Mar 1, 2025
32a7aa9
feat: add IsEmptyOrWhiteSpace for ReadOnlySpan<Char>
feO2x Mar 1, 2025
e8db798
feat: add IsEmptyOrWhiteSpace for Memory<T> and ReadOnlyMemory<T>
feO2x Mar 1, 2025
dc005d1
Merge pull request #106 from feO2x/features/span-is-empty-or-white-space
feO2x Mar 1, 2025
ed3a0f7
feat: add IsFileExtension
feO2x Mar 1, 2025
3c8e247
refactor: rename c to character in IsFileExtension
feO2x Mar 2, 2025
88663bc
feat: add IsFileExtension overloads for Span<T> and Memory<T>
feO2x Mar 2, 2025
9ce91ea
feat: optimize email regex
feO2x Mar 2, 2025
9b93e84
Merge pull request #107 from feO2x/features/email-regex-optimization
feO2x Mar 2, 2025
64a8221
feat: add MustBeFileExtension for strings
feO2x Mar 2, 2025
03b3c50
chore: update ReSharper team-shared settings
feO2x Mar 2, 2025
1b66e61
feat: add MustBeFileExtension for Span<T> and Memory<T>
feO2x Mar 2, 2025
21b10ee
feat: add custom exception factory overloads for MustBeFileExtension …
feO2x Mar 2, 2025
47e1757
chore: remove obsolete curly braces in Test.ExceptionDummy
feO2x Mar 2, 2025
d55acce
tests: add MustBeFileExtension tests for ReadOnlySpan<char>
feO2x Mar 2, 2025
a8c2c6a
refactor: assertion in ValidFileExtensions_Span now uses ReadOnlySpan…
feO2x Mar 2, 2025
9721ef4
refactor: unify ValidFileExtensionsData in MustBeFileExtensionTests
feO2x Mar 2, 2025
92f9e3a
chore: remove obsolete comments in MustBeFileExtensionTests.cs
feO2x Mar 2, 2025
6204bc2
tests: add MustBeFileExtension tests for remaining types
feO2x Mar 2, 2025
b12570c
Merge pull request #108 from feO2x/features/is-file-extension
feO2x Mar 2, 2025
9e618de
feat: extend Email regex
feO2x Mar 2, 2025
08adfbc
feat: add IsEmailAddress overloads for Span<T> and Memory<T>
feO2x Mar 2, 2025
4b68928
feat: add MustBeEmailAddress overloads for Span<T> and Memory<T>
feO2x Mar 2, 2025
da4d18a
refactor: move valid and invalid email addresses to test classes
feO2x Mar 2, 2025
83c1cd9
tests: add tests for MustBeValidEmail for Span<T> and Memory<T>
feO2x Mar 2, 2025
6d05edb
Merge pull request #109 from feO2x/features/email-regex-update
feO2x Mar 2, 2025
cd34ecc
refactor: move Throw into own namespace
feO2x Mar 6, 2025
894c331
refactor: break Throw up into several files
feO2x Mar 6, 2025
c0eabaf
Merge pull request #110 from feO2x/features/throw-breakup
feO2x Mar 8, 2025
f2d157f
feat: add IsApproximately<T> for all types implementing INumber<T>
feO2x Mar 8, 2025
7aeddc8
feat: add MustBeApproximately
feO2x Mar 8, 2025
4e99de6
build: upgrade Light.GuardClauses.Performance to .NET 8
feO2x Mar 8, 2025
b139299
performance: add MustBeApproximatelyBenchmark
feO2x Mar 8, 2025
66be15f
feat: add MustNotBeApproximately
feO2x Mar 8, 2025
20b52ce
Merge pull request #111 from feO2x/features/generic-is-approximately
feO2x Mar 8, 2025
7d8f0d9
chore: add comment to clarify index usage in IsFileExtension method
feO2x Mar 8, 2025
38a9249
fix: IsApproximately now uses <= operator instead of the < operator
feO2x Mar 8, 2025
4c5db07
feat: add IsGreaterThanOrApproximately<T>
feO2x Mar 8, 2025
0415304
feat: add IsLessThanOrApproximately<T>
feO2x Mar 8, 2025
444ca1a
feat: add MustBeGreaterThanOrApproximately
feO2x Mar 8, 2025
b02763a
feat: add MustBeLessThanOrApproximately
feO2x Mar 8, 2025
b7c953e
Merge pull request #112 from feO2x/features/generic-is-greater-than-a…
feO2x Mar 8, 2025
34efb3d
refactor: move SpanDelegates to Light.GuardClauses.ExceptionFactory n…
feO2x Mar 9, 2025
3fa99bd
chore: update version to 13.0.0
feO2x Mar 9, 2025
4efdc7b
chore: update package release notes and copyright for 13.0.0 release
feO2x Mar 9, 2025
dbaac0a
docs: update readme for 13.0.0 release
feO2x Mar 9, 2025
fafc7be
feat: update SourceFileMerger for 13.0.0 release
feO2x Mar 9, 2025
66a804e
chore: update single source file for 13.0.0 release
feO2x Mar 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 83 additions & 17 deletions Code/Light.GuardClauses.AllProjects.sln.DotSettings

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using BenchmarkDotNet.Attributes;
using Light.GuardClauses.ExceptionFactory;
using Light.GuardClauses.Exceptions;

namespace Light.GuardClauses.Performance.CollectionAssertions
Expand Down Expand Up @@ -47,23 +48,23 @@ public static class SpanMustHaveLengthExtensions
public static Span<T> MustHaveLengthCopyByValue<T>(this Span<T> parameter, int length, string parameterName = null, string message = null)
{
if (parameter.Length != length)
Throw.InvalidSpanLength(parameter, length, parameterName, message);
Throw.InvalidSpanLength((ReadOnlySpan<T>) parameter, length, parameterName, message);
return parameter;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<T> MustHaveLengthInParameter<T>(in this Span<T> parameter, int length, string parameterName = null, string message = null)
{
if (parameter.Length != length)
Throw.InvalidSpanLength(parameter, length, parameterName, message);
Throw.InvalidSpanLength((ReadOnlySpan<T>) parameter, length, parameterName, message);
return parameter;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref Span<T> MustHaveLengthInOut<T>(ref this Span<T> parameter, int length, string parameterName = null, string message = null)
{
if (parameter.Length != length)
Throw.InvalidSpanLength(parameter, length, parameterName, message);
Throw.InvalidSpanLength((ReadOnlySpan<T>) parameter, length, parameterName, message);
return ref parameter;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BenchmarkDotNet.Attributes;
using Light.GuardClauses.ExceptionFactory;

namespace Light.GuardClauses.Performance.CommonAssertions
{
Expand Down Expand Up @@ -34,7 +35,7 @@ public bool LightGuardClausesCustomException()
public bool LightGuardClausesCustomExceptionManualInlining()
{
if (Condition)
Exceptions.Throw.CustomException(() => new ArgumentException(Message, ParameterName));
Throw.CustomException(() => new ArgumentException(Message, ParameterName));
return Condition;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using Light.GuardClauses.ExceptionFactory;
using Light.GuardClauses.Exceptions;

namespace Light.GuardClauses.Performance.CommonAssertions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using Light.GuardClauses.Exceptions;
using Light.GuardClauses.ExceptionFactory;

namespace Light.GuardClauses.Performance.CommonAssertions
{
Expand Down Expand Up @@ -56,7 +56,7 @@ public static T MustNotBeNullReferenceV1<T>(this T parameter, string parameterNa
return parameter;

Throw.ArgumentNull(parameterName, message);
return default(T);
return default;
}

return parameter;
Expand All @@ -71,7 +71,7 @@ public static T MustNotBeNullReferenceV2<T>(this T parameter, string parameterNa
return parameter;

Throw.ArgumentNull(parameterName, message);
return default(T);
return default;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using BenchmarkDotNet.Attributes;

namespace Light.GuardClauses.Performance.ComparableAssertions;

[MemoryDiagnoser]
// ReSharper disable once ClassCanBeSealed.Global -- Benchmark.NET derives from this class with dynamically created code
public class MustBeApproximatelyBenchmark
{
[Benchmark]
public double MustBeApproximately() => 5.100001.MustBeApproximately(5.100000, 0.0001);

[Benchmark(Baseline = true)]
public double Imperative() => Imperative(5.100001, 5.100000, 0.0001);

private static double Imperative(double parameter, double other, double tolerance)
{
if (Math.Abs(parameter - other) > tolerance)
{
throw new ArgumentOutOfRangeException(nameof(parameter), $"Value is not approximately {other}");
}

return parameter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using BenchmarkDotNet.Attributes;

namespace Light.GuardClauses.Performance.ComparableAssertions;

[MemoryDiagnoser]
// ReSharper disable once ClassCanBeSealed.Global -- Benchmark.NET derives from this class with dynamically created code
public class MustNotBeApproximatelyBenchmark
{
[Benchmark]
public double MustNotBeApproximately() => 5.2.MustNotBeApproximately(5.1, 0.5);

[Benchmark(Baseline = true)]
public double Imperative() => Imperative(5.2, 5.1, 0.5);

private static double Imperative(double parameter, double other, double tolerance)
{
if (Math.Abs(parameter - other) < tolerance)
{
throw new ArgumentOutOfRangeException(nameof(parameter), $"Value is approximately {other}");
}

return parameter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<ProjectReference Include="..\Light.GuardClauses\Light.GuardClauses.csproj" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.9" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>

</Project>
23 changes: 11 additions & 12 deletions Code/Light.GuardClauses.Performance/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;

namespace Light.GuardClauses.Performance
namespace Light.GuardClauses.Performance;

public static class Program
{
public static class Program
{
private static IConfig DefaultConfiguration =>
DefaultConfig
.Instance
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core70))
.AddJob(Job.Default.WithRuntime(ClrRuntime.Net48))
.AddDiagnoser(MemoryDiagnoser.Default, new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig()));
private static IConfig DefaultConfiguration =>
DefaultConfig
.Instance
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80))
.AddJob(Job.Default.WithRuntime(ClrRuntime.Net48))
.AddDiagnoser(MemoryDiagnoser.Default, new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig()));

public static void Main(string[] arguments) =>
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(arguments, DefaultConfiguration);
}
public static void Main(string[] arguments) =>
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(arguments, DefaultConfiguration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<LangVersion>12.0</LangVersion>
<Authors>Kenny Pflug</Authors>
<Company>Kenny Pflug</Company>
<Copyright>Copyright © Kenny Pflug 2016 - 2023</Copyright>
<Copyright>Copyright © Kenny Pflug 2016, 2025</Copyright>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Memory" Version="4.6.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.13.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading