Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
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
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
86 changes: 70 additions & 16 deletions Code/Light.GuardClauses.AllProjects.sln.DotSettings

Large diffs are not rendered by default.

79 changes: 71 additions & 8 deletions Code/Light.GuardClauses.sln.DotSettings

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Code/Light.GuardClauses/CallerArgumentExpressionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// ReSharper disable once CheckNamespace -- CallerArgumentExpression must be in exactly this namespace
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[AttributeUsage(AttributeTargets.Parameter)]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
public CallerArgumentExpressionAttribute(string parameterName)
{
public CallerArgumentExpressionAttribute(string parameterName) =>
ParameterName = parameterName;
}

public string ParameterName { get; }
}
#endif
#endif
714 changes: 0 additions & 714 deletions Code/Light.GuardClauses/Check.CommonAssertions.cs

This file was deleted.

411 changes: 0 additions & 411 deletions Code/Light.GuardClauses/Check.ComparableAssertions.cs

This file was deleted.

28 changes: 28 additions & 0 deletions Code/Light.GuardClauses/Check.Contains.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute;

namespace Light.GuardClauses;

public static partial class Check
{
/// <summary>
/// Checks if the string contains the specified value using the given comparison type.
/// </summary>
/// <param name="string">The string to be checked.</param>
/// <param name="value">The other string.</param>
/// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
/// <returns>True if <paramref name="string" /> contains <paramref name="value" />, else false.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="string" /> or <paramref name="value" /> is null.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid <see cref="StringComparison" /> value.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[ContractAnnotation("string:null => halt; value:null => halt")]
public static bool Contains(
// ReSharper disable once RedundantNullableFlowAttribute -- Caller might have NRTs turned off
[NotNull] [ValidatedNotNull] this string @string,
string value,
StringComparison comparisonType
) =>
@string.MustNotBeNull(nameof(@string)).IndexOf(value.MustNotBeNull(nameof(value)), comparisonType) >= 0;
}
99 changes: 0 additions & 99 deletions Code/Light.GuardClauses/Check.DateTimeAssertions.cs

This file was deleted.

76 changes: 76 additions & 0 deletions Code/Light.GuardClauses/Check.DerivesFrom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#if NET8_0
using System.Diagnostics.CodeAnalysis;
#endif
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute;

// ReSharper disable RedundantNullableFlowAttribute -- NotNull has an effect, see Issue72NotNullAttributeTests


namespace Light.GuardClauses;

public static partial class Check
{
/// <summary>
/// Checks if the specified type derives from the other type. Internally, this method uses <see cref="IsEquivalentTypeTo" />
/// by default so that constructed generic types and their corresponding generic type definitions are regarded as equal.
/// </summary>
/// <param name="type">The type info to be checked.</param>
/// <param name="baseClass">The base class that <paramref name="type" /> should derive from.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="type" /> or <paramref name="baseClass" /> is null.</exception>
[ContractAnnotation("type:null => halt; baseClass:null => halt")]
public static bool DerivesFrom(
[NotNull] [ValidatedNotNull] this Type type,
[NotNull] [ValidatedNotNull] Type baseClass
)
{
baseClass.MustNotBeNull(nameof(baseClass));

var currentBaseType = type.MustNotBeNull(nameof(type)).BaseType;
while (currentBaseType != null)
{
if (currentBaseType.IsEquivalentTypeTo(baseClass))
{
return true;
}

currentBaseType = currentBaseType.BaseType;
}

return false;
}

/// <summary>
/// Checks if the specified type derives from the other type. This overload uses the specified <paramref name="typeComparer" />
/// to compare the types.
/// </summary>
/// <param name="type">The type info to be checked.</param>
/// <param name="baseClass">The base class that <paramref name="type" /> should derive from.</param>
/// <param name="typeComparer">The equality comparer used to compare the types.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="type" />, or <paramref name="baseClass" />, or <paramref name="typeComparer" /> is null.</exception>
[ContractAnnotation("type:null => halt; baseClass:null => halt; typeComparer:null => halt")]
public static bool DerivesFrom(
[NotNull] [ValidatedNotNull] this Type type,
[NotNull] [ValidatedNotNull] Type baseClass,
[NotNull] [ValidatedNotNull] IEqualityComparer<Type> typeComparer
)
{
baseClass.MustNotBeNull(nameof(baseClass));
typeComparer.MustNotBeNull(nameof(typeComparer));

var currentBaseType = type.MustNotBeNull(nameof(type)).BaseType;
while (currentBaseType != null)
{
if (typeComparer.Equals(currentBaseType, baseClass))
{
return true;
}

currentBaseType = currentBaseType.BaseType;
}

return false;
}
}
Loading
Loading