Skip to content

Commit 99658f1

Browse files
authored
Merge pull request #165 from AArnott/CallerArgumentExpression
Use `[CallerArgumentExpression]` to simplify calling patterns into `Requires` class
2 parents c159bac + 8efc0ee commit 99658f1

File tree

6 files changed

+71
-38
lines changed

6 files changed

+71
-38
lines changed

src/Microsoft.VisualStudio.Validation/Assumes.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics.CodeAnalysis;
77
using System.Globalization;
88
using System.Runtime;
9+
using System.Runtime.CompilerServices;
910

1011
namespace Microsoft;
1112

@@ -128,7 +129,7 @@ public static void Is<T>([NotNull] object? value)
128129
/// </summary>
129130
[DebuggerStepThrough]
130131
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
131-
public static void False([DoesNotReturnIf(true)] bool condition, [Localizable(false)] string? message = null)
132+
public static void False([DoesNotReturnIf(true)] bool condition, [CallerArgumentExpression(nameof(condition)), Localizable(false)] string? message = null)
132133
{
133134
if (condition)
134135
{
@@ -167,7 +168,7 @@ public static void False([DoesNotReturnIf(true)] bool condition, [Localizable(fa
167168
/// </summary>
168169
[DebuggerStepThrough]
169170
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
170-
public static void True([DoesNotReturnIf(false)] bool condition, [Localizable(false)] string? message = null)
171+
public static void True([DoesNotReturnIf(false)] bool condition, [CallerArgumentExpression(nameof(condition)), Localizable(false)] string? message = null)
171172
{
172173
if (!condition)
173174
{

src/Microsoft.VisualStudio.Validation/Microsoft.VisualStudio.Validation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
44
<RootNamespace>Microsoft</RootNamespace>
55

66
<Description>Common input validation and state verification utility methods.</Description>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
#if !NET5_0_OR_GREATER
5+
6+
#pragma warning disable SA1649 // File name should match first type name
7+
#pragma warning disable SA1600 // Elements should be documented
8+
9+
namespace System.Runtime.CompilerServices
10+
{
11+
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
12+
internal sealed class CallerArgumentExpressionAttribute : Attribute
13+
{
14+
internal CallerArgumentExpressionAttribute(string parameterName)
15+
{
16+
}
17+
}
18+
}
19+
20+
#endif

0 commit comments

Comments
 (0)