Skip to content

Commit 06c41e2

Browse files
authored
Merge pull request #103 from feO2x/smaller-files-refactoring
Smaller files refactoring
2 parents f484c96 + e357f99 commit 06c41e2

File tree

116 files changed

+6606
-4242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+6606
-4242
lines changed

Code/Light.GuardClauses.AllProjects.sln.DotSettings

Lines changed: 70 additions & 16 deletions
Large diffs are not rendered by default.

Code/Light.GuardClauses.sln.DotSettings

Lines changed: 71 additions & 8 deletions
Large diffs are not rendered by default.

Code/Light.GuardClauses/CallerArgumentExpressionAttribute.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
// ReSharper disable once CheckNamespace -- CallerArgumentExpression must be in exactly this namespace
33
namespace System.Runtime.CompilerServices;
44

5-
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
5+
[AttributeUsage(AttributeTargets.Parameter)]
66
internal sealed class CallerArgumentExpressionAttribute : Attribute
77
{
8-
public CallerArgumentExpressionAttribute(string parameterName)
9-
{
8+
public CallerArgumentExpressionAttribute(string parameterName) =>
109
ParameterName = parameterName;
11-
}
1210

1311
public string ParameterName { get; }
1412
}
15-
#endif
13+
#endif

Code/Light.GuardClauses/Check.CommonAssertions.cs

Lines changed: 0 additions & 714 deletions
This file was deleted.

Code/Light.GuardClauses/Check.ComparableAssertions.cs

Lines changed: 0 additions & 411 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
using JetBrains.Annotations;
4+
using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute;
5+
6+
namespace Light.GuardClauses;
7+
8+
public static partial class Check
9+
{
10+
/// <summary>
11+
/// Checks if the string contains the specified value using the given comparison type.
12+
/// </summary>
13+
/// <param name="string">The string to be checked.</param>
14+
/// <param name="value">The other string.</param>
15+
/// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
16+
/// <returns>True if <paramref name="string" /> contains <paramref name="value" />, else false.</returns>
17+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="string" /> or <paramref name="value" /> is null.</exception>
18+
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid <see cref="StringComparison" /> value.</exception>
19+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
20+
[ContractAnnotation("string:null => halt; value:null => halt")]
21+
public static bool Contains(
22+
// ReSharper disable once RedundantNullableFlowAttribute -- Caller might have NRTs turned off
23+
[NotNull] [ValidatedNotNull] this string @string,
24+
string value,
25+
StringComparison comparisonType
26+
) =>
27+
@string.MustNotBeNull(nameof(@string)).IndexOf(value.MustNotBeNull(nameof(value)), comparisonType) >= 0;
28+
}

Code/Light.GuardClauses/Check.DateTimeAssertions.cs

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#if NET8_0
2+
using System.Diagnostics.CodeAnalysis;
3+
#endif
4+
using System;
5+
using System.Collections.Generic;
6+
using JetBrains.Annotations;
7+
using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute;
8+
9+
// ReSharper disable RedundantNullableFlowAttribute -- NotNull has an effect, see Issue72NotNullAttributeTests
10+
11+
12+
namespace Light.GuardClauses;
13+
14+
public static partial class Check
15+
{
16+
/// <summary>
17+
/// Checks if the specified type derives from the other type. Internally, this method uses <see cref="IsEquivalentTypeTo" />
18+
/// by default so that constructed generic types and their corresponding generic type definitions are regarded as equal.
19+
/// </summary>
20+
/// <param name="type">The type info to be checked.</param>
21+
/// <param name="baseClass">The base class that <paramref name="type" /> should derive from.</param>
22+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="type" /> or <paramref name="baseClass" /> is null.</exception>
23+
[ContractAnnotation("type:null => halt; baseClass:null => halt")]
24+
public static bool DerivesFrom(
25+
[NotNull] [ValidatedNotNull] this Type type,
26+
[NotNull] [ValidatedNotNull] Type baseClass
27+
)
28+
{
29+
baseClass.MustNotBeNull(nameof(baseClass));
30+
31+
var currentBaseType = type.MustNotBeNull(nameof(type)).BaseType;
32+
while (currentBaseType != null)
33+
{
34+
if (currentBaseType.IsEquivalentTypeTo(baseClass))
35+
{
36+
return true;
37+
}
38+
39+
currentBaseType = currentBaseType.BaseType;
40+
}
41+
42+
return false;
43+
}
44+
45+
/// <summary>
46+
/// Checks if the specified type derives from the other type. This overload uses the specified <paramref name="typeComparer" />
47+
/// to compare the types.
48+
/// </summary>
49+
/// <param name="type">The type info to be checked.</param>
50+
/// <param name="baseClass">The base class that <paramref name="type" /> should derive from.</param>
51+
/// <param name="typeComparer">The equality comparer used to compare the types.</param>
52+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="type" />, or <paramref name="baseClass" />, or <paramref name="typeComparer" /> is null.</exception>
53+
[ContractAnnotation("type:null => halt; baseClass:null => halt; typeComparer:null => halt")]
54+
public static bool DerivesFrom(
55+
[NotNull] [ValidatedNotNull] this Type type,
56+
[NotNull] [ValidatedNotNull] Type baseClass,
57+
[NotNull] [ValidatedNotNull] IEqualityComparer<Type> typeComparer
58+
)
59+
{
60+
baseClass.MustNotBeNull(nameof(baseClass));
61+
typeComparer.MustNotBeNull(nameof(typeComparer));
62+
63+
var currentBaseType = type.MustNotBeNull(nameof(type)).BaseType;
64+
while (currentBaseType != null)
65+
{
66+
if (typeComparer.Equals(currentBaseType, baseClass))
67+
{
68+
return true;
69+
}
70+
71+
currentBaseType = currentBaseType.BaseType;
72+
}
73+
74+
return false;
75+
}
76+
}

0 commit comments

Comments
 (0)