Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions src/Fusillade/ArgumentExceptionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Fusillade.Helpers;

/// <summary>
/// Provides helper methods for argument validation.
/// These methods serve as polyfills for ArgumentExceptionHelper.ThrowIfNull and related methods
/// that are only available in newer .NET versions.
/// </summary>
[ExcludeFromCodeCoverage]
internal static class ArgumentExceptionHelper
{
/// <summary>
/// Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is null.
/// </summary>
/// <param name="argument">The reference type argument to validate as non-null.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="argument"/> corresponds.</param>
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is null)
{
throw new ArgumentNullException(paramName);
}
}

/// <summary>
/// Throws an exception if <paramref name="argument"/> is null or empty.
/// </summary>
/// <param name="argument">The string argument to validate as non-null and non-empty.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="argument"/> corresponds.</param>
/// <exception cref="ArgumentNullException"><paramref name="argument"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="argument"/> is empty.</exception>
public static void ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is null)
{
throw new ArgumentNullException(paramName);
}

if (argument.Length == 0)
{
throw new ArgumentException("The value cannot be an empty string.", paramName);
}
}
}
12 changes: 3 additions & 9 deletions src/Fusillade/Builder/FusilladeSplatBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using Fusillade;
using Fusillade.Helpers;

namespace Splat.Builder;

Expand All @@ -20,14 +21,7 @@ public static class FusilladeSplatBuilderExtensions
/// <returns>The App Instance for Chaining.</returns>
public static IAppInstance CreateFusilladeNetCache(this IAppInstance builder)
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(builder);
#else
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
#endif
ArgumentExceptionHelper.ThrowIfNull(builder);

NetCache.CreateDefaultInstances(builder.Current);
return builder;
Expand Down
2 changes: 1 addition & 1 deletion src/Fusillade/ConcatenateMixin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand Down
2 changes: 1 addition & 1 deletion src/Fusillade/IRequestCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand Down
2 changes: 1 addition & 1 deletion src/Fusillade/InflightRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand Down
2 changes: 1 addition & 1 deletion src/Fusillade/LimitingHttpMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand Down
48 changes: 7 additions & 41 deletions src/Fusillade/NetCache.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Net.Http;
using Fusillade.Helpers;
using Punchclock;
using Splat;

Expand Down Expand Up @@ -62,14 +63,7 @@ public static LimitingHttpMessageHandler Speculative
get => unitTestSpeculative ?? GetCurrent().GetService<LimitingHttpMessageHandler>("Speculative") ?? speculative;
set
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value, nameof(value));
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
ArgumentExceptionHelper.ThrowIfNull(value, nameof(value));

if (ModeDetector.InUnitTestRunner())
{
Expand All @@ -92,14 +86,7 @@ public static HttpMessageHandler UserInitiated
get => unitTestUserInitiated ?? GetCurrent().GetService<HttpMessageHandler>("UserInitiated") ?? userInitiated;
set
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value, nameof(value));
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
ArgumentExceptionHelper.ThrowIfNull(value, nameof(value));

if (ModeDetector.InUnitTestRunner())
{
Expand All @@ -122,14 +109,7 @@ public static HttpMessageHandler Background
get => unitTestBackground ?? GetCurrent().GetService<HttpMessageHandler>("Background") ?? background;
set
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value, nameof(value));
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
ArgumentExceptionHelper.ThrowIfNull(value, nameof(value));

if (ModeDetector.InUnitTestRunner())
{
Expand All @@ -152,14 +132,7 @@ public static HttpMessageHandler Offline
get => unitTestOffline ?? GetCurrent().GetService<HttpMessageHandler>("Offline") ?? offline;
set
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value, nameof(value));
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
ArgumentExceptionHelper.ThrowIfNull(value, nameof(value));

if (ModeDetector.InUnitTestRunner())
{
Expand All @@ -183,14 +156,7 @@ public static OperationQueue OperationQueue
get => unitTestOperationQueue ?? GetCurrent().GetService<OperationQueue>("OperationQueue") ?? operationQueue;
set
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value, nameof(value));
#else
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
#endif
ArgumentExceptionHelper.ThrowIfNull(value, nameof(value));

if (ModeDetector.InUnitTestRunner())
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fusillade/OfflineHttpMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand Down
40 changes: 40 additions & 0 deletions src/Fusillade/Polyfills/CallerArgumentExpressionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2016 - 2026 ReactiveUI and Contributors. All rights reserved.
// Licensed to ReactiveUI and Contributors under one or more agreements.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

#if !NET5_0_OR_GREATER

// Polyfill implementation adapted from Simon Cropp's Polyfill library
// https://github.com/SimonCropp/Polyfill
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Runtime.CompilerServices;

/// <summary>
/// Indicates that a parameter captures the expression passed for another parameter as a string.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Parameter)]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="CallerArgumentExpressionAttribute"/> class.
/// </summary>
/// <param name="parameterName">The name of the parameter whose expression should be captured as a string.</param>
public CallerArgumentExpressionAttribute(string parameterName) =>
ParameterName = parameterName;

/// <summary>
/// Gets the name of the parameter whose expression should be captured as a string.
/// </summary>
public string ParameterName { get; }
}

#else
using System.Runtime.CompilerServices;

[assembly: TypeForwardedTo(typeof(CallerArgumentExpressionAttribute))]
#endif
Loading
Loading