Skip to content

Commit

Permalink
Simplify Guarding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Jul 8, 2023
1 parent 08b85e0 commit 3c53634
Show file tree
Hide file tree
Showing 63 changed files with 183 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TypeConverterModelBinder()
/// </param>
public TypeConverterModelBinder AddAssembly(Assembly assembly)
{
Guard.NotNull(assembly, nameof(assembly));
Guard.NotNull(assembly);
var tps = assembly
.GetTypes()
.Where(tp => !tp.IsGenericType)
Expand All @@ -56,7 +56,7 @@ public TypeConverterModelBinder AddAssembly(Assembly assembly)
/// </remarks>
public TypeConverterModelBinder AddTypes(params Type[] tps)
{
Guard.NotNull(tps, nameof(tps));
Guard.NotNull(tps);
foreach (var tp in tps)
{
AddType(tp);
Expand Down Expand Up @@ -94,7 +94,7 @@ public TypeConverterModelBinder AddType(Type tp)
/// <inheritdoc />
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
Guard.NotNull(context, nameof(context));
Guard.NotNull(context);

var type = QowaivType.GetNotNullableType(context.Metadata?.ModelType);

Expand All @@ -106,7 +106,7 @@ public IModelBinder GetBinder(ModelBinderProviderContext context)
/// <inheritdoc />
public Task BindModelAsync(ModelBindingContext bindingContext)
{
Guard.NotNull(bindingContext, nameof(bindingContext));
Guard.NotNull(bindingContext);

var modelName = bindingContext.ModelName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static TypeConverterModelBinder()
/// </param>
public static void AddAssembly(Assembly assembly)
{
Guard.NotNull(assembly, nameof(assembly));
Guard.NotNull(assembly);
var tps = assembly.GetTypes()
.Where(tp => tp.GetCustomAttribute<SingleValueObjectAttribute>() != null)
.ToArray();
Expand All @@ -53,7 +53,7 @@ public static void AddAssembly(Assembly assembly)
/// </remarks>
public static void AddTypes(params Type[] tps)
{
Guard.NotNull(tps, nameof(tps));
Guard.NotNull(tps);
foreach (var tp in tps)
{
AddType(tp);
Expand Down Expand Up @@ -106,7 +106,7 @@ public static void AddType(Type tp)
/// </remarks>
public static void RegisterForAll(ModelBinderDictionary binders)
{
Guard.NotNull(binders, nameof(binders));
Guard.NotNull(binders);
foreach (var tp in TypeConverters.Keys)
{
binders.Add(tp, Instance);
Expand All @@ -128,7 +128,7 @@ public static void RegisterForAll(ModelBinderDictionary binders)
/// <returns>The bound model.</returns>
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
Guard.NotNull(bindingContext, nameof(bindingContext));
Guard.NotNull(bindingContext);

// Get the value result.
var valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
Expand Down
8 changes: 4 additions & 4 deletions src/Qowaiv.Data.SqlClient/Generated/Timestamp.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ public partial struct Timestamp : ISerializable
/// <param name="context">The streaming context.</param>
private Timestamp(SerializationInfo info, StreamingContext context)
{
Guard.NotNull(info, nameof(info));
Guard.NotNull(info);
m_Value = info.GetValue("Value", typeof(ulong)) is ulong val ? val : default(ulong);
}

/// <summary>Adds the underlying property of the timestamp to the serialization info.</summary>
/// <param name="info">The serialization info.</param>
/// <param name="context">The streaming context.</param>
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
=> Guard.NotNull(info, nameof(info)).AddValue("Value", m_Value);
=> Guard.NotNull(info).AddValue("Value", m_Value);
}

public partial struct Timestamp
Expand Down Expand Up @@ -145,7 +145,7 @@ public partial struct Timestamp : IXmlSerializable
/// <param name="reader">An XML reader.</param>
void IXmlSerializable.ReadXml(XmlReader reader)
{
Guard.NotNull(reader, nameof(reader));
Guard.NotNull(reader);
var xml = reader.ReadElementString();
System.Runtime.CompilerServices.Unsafe.AsRef(this) = Parse(xml, CultureInfo.InvariantCulture);
}
Expand All @@ -156,7 +156,7 @@ void IXmlSerializable.ReadXml(XmlReader reader)
/// </remarks>
/// <param name="writer">An XML writer.</param>
void IXmlSerializable.WriteXml(XmlWriter writer)
=> Guard.NotNull(writer, nameof(writer)).WriteString(ToXmlString());
=> Guard.NotNull(writer).WriteString(ToXmlString());
}

public partial struct Timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class QowaivAssemblyAssertions
[CustomAssertion]
public static AndConstraint<AssemblyAssertions> HavePublicKey(this AssemblyAssertions assertions, string publicKey, string because = "", params object[] becauseArgs)
{
Guard.NotNull(assertions, nameof(assertions));
Guard.NotNull(assertions);

var bytes = assertions.Subject.GetName().GetPublicKey() ?? Array.Empty<byte>();
var assemblyKey = BitConverter.ToString(bytes).Replace("-", string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class QowaivAssemblyAssertions
[CustomAssertion]
public static AndConstraint<AssemblyAssertions> HavePublicKey(this AssemblyAssertions assertions, string publicKey, string because = "", params object[] becauseArgs)
{
Guard.NotNull(assertions, nameof(assertions));
Guard.NotNull(assertions);

var bytes = assertions.Subject.GetName().GetPublicKey() ?? Array.Empty<byte>();
var assemblyKey = BitConverter.ToString(bytes).Replace("-", string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class QowaivDebuggerDisplayAssertions
string because = "",
params object[] becauseArgs)
{
var prop = DebuggerDisplay(Guard.NotNull(assertions, nameof(assertions)).Subject.GetType());
var prop = DebuggerDisplay(Guard.NotNull(assertions).Subject.GetType());

if (Execute.Assertion
.ForCondition(prop is { })
Expand All @@ -37,7 +37,7 @@ public static class QowaivDebuggerDisplayAssertions
string because = "",
params object[] becauseArgs)
{
var prop = DebuggerDisplay(Guard.NotNull(assertions, nameof(assertions)).Subject.GetType());
var prop = DebuggerDisplay(Guard.NotNull(assertions).Subject.GetType());

if (Execute.Assertion
.ForCondition(prop is { })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class QowaivTypeConverterAssertions
[CustomAssertion]
public static AndConstraint<TypeAssertions> HaveTypeConverterDefined(this TypeAssertions assertions, string because = "", params object[] becauseArgs)
{
Guard.NotNull(assertions, nameof(assertions));
Guard.NotNull(assertions);

var converter = TypeDescriptor.GetConverter(assertions.Subject);

Expand Down
18 changes: 9 additions & 9 deletions src/Qowaiv/Clock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static DateTime UtcNow()
/// The specified time zone.
/// </param>
[Pure]
public static LocalDateTime Now(TimeZoneInfo timeZone) => TimeZoneInfo.ConvertTimeFromUtc(UtcNow(), Guard.NotNull(timeZone, nameof(timeZone)));
public static LocalDateTime Now(TimeZoneInfo timeZone) => TimeZoneInfo.ConvertTimeFromUtc(UtcNow(), Guard.NotNull(timeZone));

/// <summary>Gets the current <see cref="DateTimeOffset"/>.</summary>
[Pure]
Expand All @@ -69,7 +69,7 @@ public static DateTime UtcNow()
[Pure]
public static DateTimeOffset NowWithOffset(TimeZoneInfo timeZone)
{
Guard.NotNull(timeZone, nameof(timeZone));
Guard.NotNull(timeZone);
var utcNow = UtcNow();
var now = TimeZoneInfo.ConvertTimeFromUtc(utcNow, timeZone);
return new DateTimeOffset(now.Ticks, now - utcNow);
Expand Down Expand Up @@ -97,7 +97,7 @@ public static DateTimeOffset NowWithOffset(TimeZoneInfo timeZone)
[Pure]
public static Date Today(TimeZoneInfo timeZone)
{
Guard.NotNull(timeZone, nameof(timeZone));
Guard.NotNull(timeZone);
return (Date)TimeZoneInfo.ConvertTimeFromUtc(UtcNow(), timeZone);
}

Expand All @@ -116,13 +116,13 @@ public static Date Today(TimeZoneInfo timeZone)
/// <remarks>
/// For test purposes use <see cref="SetLocalContextUtcNow(Func{DateTime})"/>.
/// </remarks>
public static void SetTime(Func<DateTime> time) => globalUtcNow = Guard.NotNull(time, nameof(time));
public static void SetTime(Func<DateTime> time) => globalUtcNow = Guard.NotNull(time);

/// <summary>Sets the <see cref="TimeZoneInfo"/> function globally (for the full Application Domain).</summary>
/// <remarks>
/// For test purposes use <see cref="SetTimeZoneForCurrentContext(TimeZoneInfo)"/>.
/// </remarks>
public static void SetTimeZone(TimeZoneInfo timeZone) => globalTimeZone = Guard.NotNull(timeZone, nameof(timeZone));
public static void SetTimeZone(TimeZoneInfo timeZone) => globalTimeZone = Guard.NotNull(timeZone);

/// <summary>Sets the <see cref="DateTime"/> function for current (execution) context only.</summary>
[Impure]
Expand Down Expand Up @@ -168,7 +168,7 @@ private sealed class TimeScope : IDisposable
public TimeScope(Func<DateTime> time)
{
_func = localContextUtcNow.Value;
SetLocalContextUtcNow(Guard.NotNull(time, nameof(time)));
SetLocalContextUtcNow(Guard.NotNull(time));
}

private readonly Func<DateTime>? _func;
Expand All @@ -182,7 +182,7 @@ private sealed class TimeZoneScope : IDisposable
public TimeZoneScope(TimeZoneInfo timeZone)
{
_zone = localContextTimeZone.Value;
SetLocalContextTimeZone(Guard.NotNull(timeZone, nameof(timeZone)));
SetLocalContextTimeZone(Guard.NotNull(timeZone));
}

private readonly TimeZoneInfo? _zone;
Expand All @@ -197,8 +197,8 @@ public ClockScope(Func<DateTime> time, TimeZoneInfo timeZone)
{
_func = localContextUtcNow.Value;
_zone = localContextTimeZone.Value;
SetLocalContextUtcNow(Guard.NotNull(time, nameof(time)));
SetLocalContextTimeZone(Guard.NotNull(timeZone, nameof(timeZone)));
SetLocalContextUtcNow(Guard.NotNull(time));
SetLocalContextTimeZone(Guard.NotNull(timeZone));
}

private readonly Func<DateTime>? _func;
Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv/Conversion/Customization/SvoTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class SvoTypeConverter : TypeConverter
/// </param>
public SvoTypeConverter(Type type)
{
Guard.NotNull(type, nameof(type));
Guard.NotNull(type);

if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Svo<>) && type.GetGenericArguments().Length == 1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv/Conversion/DateTypeConverter_T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
[Pure]
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
Guard.NotNull(destinationType, nameof(destinationType));
Guard.NotNull(destinationType);

// If the value is null or default value.
if (QowaivType.IsNullOrDefaultValue(value))
Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv/Conversion/Identifiers/IdTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class IdTypeConverter : TypeConverter
/// </param>
public IdTypeConverter(Type type)
{
Guard.NotNull(type, nameof(type));
Guard.NotNull(type);

if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Id<>) && type.GetGenericArguments().Length == 1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv/Conversion/NumericTypeConverter_TSvo_TRaw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
[Pure]
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
Guard.NotNull(destinationType, nameof(destinationType));
Guard.NotNull(destinationType);

// If the value is null or default value.
if (QowaivType.IsNullOrDefaultValue(value))
Expand Down
8 changes: 4 additions & 4 deletions src/Qowaiv/Customization/Svo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ namespace Qowaiv.Customization;
/// <param name="context">The streaming context.</param>
private Svo(SerializationInfo info, StreamingContext context)
{
Guard.NotNull(info, nameof(info));
Guard.NotNull(info);
m_Value = Parse(info.GetString("Value")).m_Value;
}

/// <summary>Adds the underlying property of the Single Value Object to the serialization info.</summary>
/// <param name="info">The serialization info.</param>
/// <param name="context">The streaming context.</param>
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
=> Guard.NotNull(info, nameof(info)).AddValue("Value", m_Value);
=> Guard.NotNull(info).AddValue("Value", m_Value);

/// <summary>The inner value of the Single Value Object.</summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Expand Down Expand Up @@ -164,7 +164,7 @@ public string ToString(string? format, IFormatProvider? formatProvider)
/// <param name="reader">An XML reader.</param>
void IXmlSerializable.ReadXml(XmlReader reader)
{
Guard.NotNull(reader, nameof(reader));
Guard.NotNull(reader);
var xml = reader.ReadElementString();
System.Runtime.CompilerServices.Unsafe.AsRef(this) = Parse(xml, CultureInfo.InvariantCulture);
}
Expand All @@ -175,7 +175,7 @@ void IXmlSerializable.ReadXml(XmlReader reader)
/// </remarks>
/// <param name="writer">An XML writer.</param>
void IXmlSerializable.WriteXml(XmlWriter writer)
=> Guard.NotNull(writer, nameof(writer)).WriteString(ToXmlString());
=> Guard.NotNull(writer).WriteString(ToXmlString());

/// <summary>Gets an XML string representation of the Single Value Object.</summary>
[Pure]
Expand Down
10 changes: 5 additions & 5 deletions src/Qowaiv/EmailAddressCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public bool Add(EmailAddress item)
/// <summary>Keeps only the distinct set of email addresses in the collection.</summary>
public void AddRange(IEnumerable<EmailAddress> emails)
{
Guard.NotNull(emails, nameof(emails));
Guard.NotNull(emails);
foreach (var email in emails)
{
Add(email);
Expand Down Expand Up @@ -171,7 +171,7 @@ public void AddRange(IEnumerable<EmailAddress> emails)
protected EmailAddressCollection(SerializationInfo info, StreamingContext context)
: this()
{
Guard.NotNull(info, nameof(info));
Guard.NotNull(info);
AddRange(Parse(info.GetString("Value"), CultureInfo.InvariantCulture));
}

Expand All @@ -186,7 +186,7 @@ protected EmailAddressCollection(SerializationInfo info, StreamingContext contex
/// </remarks>
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
Guard.NotNull(info, nameof(info));
Guard.NotNull(info);
info.AddValue("Value", ToString());
}

Expand Down Expand Up @@ -215,7 +215,7 @@ protected virtual void GetObjectData(SerializationInfo info, StreamingContext co
/// </remarks>
protected virtual void ReadXml(XmlReader reader)
{
Guard.NotNull(reader, nameof(reader));
Guard.NotNull(reader);
var s = reader.ReadElementString();
var val = Parse(s, CultureInfo.InvariantCulture);
AddRange(val);
Expand All @@ -232,7 +232,7 @@ protected virtual void ReadXml(XmlReader reader)
/// </remarks>
protected virtual void WriteXml(XmlWriter writer)
{
Guard.NotNull(writer, nameof(writer));
Guard.NotNull(writer);
writer.WriteString(ToString(CultureInfo.InvariantCulture));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv/Extensions/System.IO.DirectoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class QowaivDirectoryInfoExtensions
/// <summary>Gets the stream size of the current directory.</summary>
[Pure]
public static StreamSize GetStreamSize(this DirectoryInfo directoryInfo)
=> Guard.NotNull(directoryInfo, nameof(directoryInfo))
=> Guard.NotNull(directoryInfo)
.EnumerateFiles("*", SearchOption.AllDirectories)
.Sum(file => file.Length);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public static class QowaivHashAlgorithmExtensions
[Pure]
public static CryptographicSeed ComputeCryptographicSeed(this HashAlgorithm algorithm, byte[]? buffer)
=> buffer is { }
? CryptographicSeed.Create(Guard.NotNull(algorithm, nameof(algorithm)).ComputeHash(buffer))
? CryptographicSeed.Create(Guard.NotNull(algorithm).ComputeHash(buffer))
: CryptographicSeed.Empty;
}
6 changes: 3 additions & 3 deletions src/Qowaiv/Extensions/System.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class QowaivSystemExtensions
[Pure]
public static string ToUpper(this string str, IFormatProvider provider)
{
Guard.NotNull(provider, nameof(provider));
Guard.NotNull(provider);
var textInfo = provider.GetFormat<TextInfo>() ?? CultureInfo.CurrentCulture.TextInfo;
return textInfo.ToUpper(str);
}
Expand All @@ -42,7 +42,7 @@ public static string ToUpper(this string str, IFormatProvider provider)
[Pure]
public static string ToTitleCase(this string str, IFormatProvider provider)
{
Guard.NotNull(provider, nameof(provider));
Guard.NotNull(provider);
var textInfo = provider.GetFormat<TextInfo>() ?? CultureInfo.CurrentCulture.TextInfo;
return textInfo.ToTitleCase(str);
}
Expand All @@ -58,7 +58,7 @@ public static string ToTitleCase(this string str, IFormatProvider provider)
[Pure]
public static TFormat? GetFormat<TFormat>(this IFormatProvider provider)
{
Guard.NotNull(provider, nameof(provider));
Guard.NotNull(provider);
return (TFormat?)provider.GetFormat(typeof(TFormat));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv/Extensions/System.Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class QowaivTypeExtensions
[Pure]
public static string ToCSharpString(this Type type, bool withNamespace)
{
Guard.NotNull(type, nameof(type));
Guard.NotNull(type);
return new StringBuilder().AppendType(type, withNamespace).ToString();
}

Expand Down
Loading

0 comments on commit 3c53634

Please sign in to comment.