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

Take this explicitly to avoid argument shuffling by caller #111084

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public override int GetMaxByteCount(int charCount)
if ((uint)charCount > (int.MaxValue / MaxUtf8BytesPerChar) - 1)
{
// Move the throw out of the hot path to allow for inlining.
ThrowArgumentException(charCount);
static void ThrowArgumentException(int charCount)
ThrowArgumentException(this, charCount);
#pragma warning disable IDE0060 // 'this' taken explicitly to avoid argument shuffling by caller
static void ThrowArgumentException(object @this, int charCount)
#pragma warning restore IDE0060
{
throw new ArgumentOutOfRangeException(
paramName: nameof(charCount),
Expand All @@ -103,8 +105,10 @@ public override int GetMaxCharCount(int byteCount)
if ((uint)byteCount > int.MaxValue - 1)
{
// Move the throw out of the hot path to allow for inlining.
ThrowArgumentException(byteCount);
static void ThrowArgumentException(int byteCount)
ThrowArgumentException(this, byteCount);
#pragma warning disable IDE0060 // 'this' taken explicitly to avoid argument shuffling by caller
static void ThrowArgumentException(object @this, int byteCount)
#pragma warning restore IDE0060
{
throw new ArgumentOutOfRangeException(
paramName: nameof(byteCount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,14 @@ internal override void InnerInvoke()
if ((options & ~(ConfigureAwaitOptions.ContinueOnCapturedContext |
ConfigureAwaitOptions.ForceYielding)) != 0)
{
ThrowForInvalidOptions(options);
ThrowForInvalidOptions(this, options);
}

return new ConfiguredTaskAwaitable<TResult>(this, options);

static void ThrowForInvalidOptions(ConfigureAwaitOptions options) =>
#pragma warning disable IDE0060 // 'this' taken explicitly to avoid argument shuffling by caller
static void ThrowForInvalidOptions(object @this, ConfigureAwaitOptions options) =>
#pragma warning restore IDE0060
throw ((options & ConfigureAwaitOptions.SuppressThrowing) == 0 ?
new ArgumentOutOfRangeException(nameof(options)) :
new ArgumentOutOfRangeException(nameof(options), SR.TaskT_ConfigureAwait_InvalidOptions));
Expand Down