Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got rid of IDE0066, IDE0250, IDE0063 warnings #1930

Merged
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
6 changes: 3 additions & 3 deletions src/Polly/Polly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<ProjectType>Library</ProjectType>
<MutationScore>70</MutationScore>
<IncludePollyUsings>true</IncludePollyUsings>
<NoWarn>$(NoWarn);IDE0011;SA1501;S103;IDE0055;SA1111;IDE0066;S3872;SA1127;SA1128;SA1402;SA1513;SA1414;S3215;S2955</NoWarn>
<NoWarn>$(NoWarn);IDE0011;SA1501;S103;IDE0055;SA1111;S3872;SA1127;SA1128;SA1402;SA1513;SA1414;S3215;S2955</NoWarn>
<NoWarn>$(NoWarn);IDE1006;CA1062;S107;CA1068;S4039;SA1121;CA1000;CA1063;SA1113;CA1031;CA1051;CA1200</NoWarn>
<NoWarn>$(NoWarn);SA1629;SA1612;CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;IDE0250;S109;SA1618;SA1407;CA1033</NoWarn>
<NoWarn>$(NoWarn);SA1515;S4023;CA1010;IDE0063;S2681;S3442;S3880;CA1064;SA1110;SA1203;SA1649;SA1625;SA1623;SA1118</NoWarn>
<NoWarn>$(NoWarn);SA1629;SA1612;CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;S109;SA1618;SA1407;CA1033</NoWarn>
<NoWarn>$(NoWarn);SA1515;S4023;CA1010;S2681;S3442;S3880;CA1064;SA1110;SA1203;SA1649;SA1625;SA1623;SA1118</NoWarn>
<NoWarn>$(NoWarn);S3253;S3971;S6605;CA1724;CA1716;SA1108;CA1710;S4049;S3246</NoWarn>
<NoWarn>$(NoWarn);SA1805;SA1805;CA1805;CA1821</NoWarn>

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Utilities/EmptyStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// A null struct for policies and actions which do not return a TResult.
/// </summary>
internal struct EmptyStruct
internal readonly struct EmptyStruct
{
internal static readonly EmptyStruct Instance;
}
2 changes: 1 addition & 1 deletion src/Polly/Utilities/TimedLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Polly.Utilities;
// Thanks to John Sands for providing the necessary incentive to make
// me invent a way of using a struct in both release and debug builds
// without losing the debug leak tracking.
internal struct TimedLock : IDisposable
internal readonly struct TimedLock : IDisposable
{
// The TimedLock class throws a LockTimeoutException if a lock cannot be obtained within the LockTimeout. This allows the easier discovery and debugging of deadlocks during Polly development, than if using a pure lock.
// We do not however ever want to throw a LockTimeoutException in production - hence the forked LockTimeout value below for DEBUG versus RELEASE builds.
Expand Down
38 changes: 12 additions & 26 deletions src/Polly/Wrap/AsyncPolicyWrapSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,13 @@ public partial class Policy
/// <param name="policies">The policies to place in the wrap, outermost (at left) to innermost (at right).</param>
/// <returns>The PolicyWrap.</returns>
/// <exception cref="ArgumentException">The enumerable of policies to form the wrap must contain at least two policies.</exception>
public static AsyncPolicyWrap WrapAsync(params IAsyncPolicy[] policies)
{
switch (policies.Length)
public static AsyncPolicyWrap WrapAsync(params IAsyncPolicy[] policies) =>
policies.Length switch
{
case 0:
case 1:
throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies));
case 2:
return new AsyncPolicyWrap((AsyncPolicy)policies[0], policies[1]);

default:
return WrapAsync(policies[0], WrapAsync(policies.Skip(1).ToArray()));
}
}
0 or 1 => throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies)),
2 => new AsyncPolicyWrap((AsyncPolicy)policies[0], policies[1]),
_ => WrapAsync(policies[0], WrapAsync(policies.Skip(1).ToArray())),
};

/// <summary>
/// Creates a <see cref="PolicyWrap" /> of the given policies governing delegates returning values of type <typeparamref name="TResult" />.
Expand All @@ -151,18 +144,11 @@ public static AsyncPolicyWrap WrapAsync(params IAsyncPolicy[] policies)
/// <typeparam name="TResult">The return type of delegates which may be executed through the policy.</typeparam>
/// <returns>The PolicyWrap.</returns>
/// <exception cref="ArgumentException">The enumerable of policies to form the wrap must contain at least two policies.</exception>
public static AsyncPolicyWrap<TResult> WrapAsync<TResult>(params IAsyncPolicy<TResult>[] policies)
{
switch (policies.Length)
public static AsyncPolicyWrap<TResult> WrapAsync<TResult>(params IAsyncPolicy<TResult>[] policies) =>
policies.Length switch
{
case 0:
case 1:
throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies));
case 2:
return new AsyncPolicyWrap<TResult>((AsyncPolicy<TResult>)policies[0], policies[1]);

default:
return WrapAsync(policies[0], WrapAsync(policies.Skip(1).ToArray()));
}
}
0 or 1 => throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies)),
2 => new AsyncPolicyWrap<TResult>((AsyncPolicy<TResult>)policies[0], policies[1]),
_ => WrapAsync(policies[0], WrapAsync(policies.Skip(1).ToArray())),
};
}
38 changes: 12 additions & 26 deletions src/Polly/Wrap/PolicyWrapSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,13 @@ public partial class Policy
/// <param name="policies">The policies to place in the wrap, outermost (at left) to innermost (at right).</param>
/// <returns>The PolicyWrap.</returns>
/// <exception cref="ArgumentException">The enumerable of policies to form the wrap must contain at least two policies.</exception>
public static PolicyWrap Wrap(params ISyncPolicy[] policies)
{
switch (policies.Length)
public static PolicyWrap Wrap(params ISyncPolicy[] policies) =>
policies.Length switch
{
case 0:
case 1:
throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies));
case 2:
return new PolicyWrap((Policy)policies[0], policies[1]);

default:
return Wrap(policies[0], Wrap(policies.Skip(1).ToArray()));
}
}
0 or 1 => throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies)),
2 => new PolicyWrap((Policy)policies[0], policies[1]),
_ => Wrap(policies[0], Wrap(policies.Skip(1).ToArray())),
};

/// <summary>
/// Creates a <see cref="PolicyWrap" /> of the given policies governing delegates returning values of type <typeparamref name="TResult" />.
Expand All @@ -151,18 +144,11 @@ public static PolicyWrap Wrap(params ISyncPolicy[] policies)
/// <typeparam name="TResult">The return type of delegates which may be executed through the policy.</typeparam>
/// <returns>The PolicyWrap.</returns>
/// <exception cref="ArgumentException">The enumerable of policies to form the wrap must contain at least two policies.</exception>
public static PolicyWrap<TResult> Wrap<TResult>(params ISyncPolicy<TResult>[] policies)
{
switch (policies.Length)
public static PolicyWrap<TResult> Wrap<TResult>(params ISyncPolicy<TResult>[] policies) =>
policies.Length switch
{
case 0:
case 1:
throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies));
case 2:
return new PolicyWrap<TResult>((Policy<TResult>)policies[0], policies[1]);

default:
return Wrap(policies[0], Wrap(policies.Skip(1).ToArray()));
}
}
0 or 1 => throw new ArgumentException("The enumerable of policies to form the wrap must contain at least two policies.", nameof(policies)),
2 => new PolicyWrap<TResult>((Policy<TResult>)policies[0], policies[1]),
_ => Wrap(policies[0], Wrap(policies.Skip(1).ToArray())),
};
}
Loading