-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathSystem.Diagnostics.CodeAnalysis.cs
76 lines (72 loc) · 3.4 KB
/
System.Diagnostics.CodeAnalysis.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#if !NETSTANDARD2_1
namespace System.Diagnostics.CodeAnalysis
{
// Effectively the Microsoft implementation for when it doesn't exist for my convenience
/// <summary>
/// Specifies that when a method returns <see cref="ReturnValue"/>,
/// the parameter may be <see langword="null"/> even if the corresponding type disallows it.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class MaybeNullWhenAttribute : Attribute
{
/// <summary>
/// Initializes the attribute with the specified return value condition.
/// </summary>
/// <param name="returnValue">The return value condition. If the method returns this
/// value, the associated parameter may be null.</param>
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
/// <summary>
/// Gets the return value condition.
/// </summary>
/// <value>The return value condition. If the method returns this value, the
/// associated parameter may be null.</value>
public bool ReturnValue { get; }
}
/// <summary>
/// Specifies that when a method returns <see cref="ReturnValue"/>,
/// the parameter is not <see langword="null"/> even if the corresponding type allows it.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class NotNullWhenAttribute : Attribute
{
/// <summary>
/// Initializes the attribute with the specified return value condition.
/// </summary>
/// <param name="returnValue">The return value condition. If the method returns this
/// value, the associated parameter is not null.</param>
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
/// <summary>
/// Gets the return value condition.
/// </summary>
/// <value>The return value condition. If the method returns this value, the
/// associated parameter is not null.</value>
public bool ReturnValue { get; }
}
/// <summary>
/// Specifies that an output may be <see langword="null"/> even if the corresponding type disallows it.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
internal sealed class MaybeNullAttribute : Attribute
{
}
/// <summary>
/// Specifies that the method will not return if the associated Boolean parameter is passed the specified value.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class DoesNotReturnIfAttribute : Attribute
{
/// <summary>
/// Initializes the attribute with the specified parameter value.
/// </summary>
/// <param name="parameterValue">
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
/// the associated parameter matches this value.
/// </param>
public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;
/// <summary>
/// Gets the condition parameter value.
/// </summary>
public bool ParameterValue { get; }
}
}
#endif