Last active
July 4, 2022 14:17
-
-
Save Denis535/cbd208ee891ef85ed9dd4c7ab8361f15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Diagnostics.CodeAnalysis { | |
// Input: field, property, argument | |
// Output: field, property, argument, result | |
// AllowNull - Null input is allowed | |
// DisallowNull - Null input is disallowed | |
// MaybeNull - Output may be null | |
// MaybeNull/When - Output may be null (when result == true/false) | |
// NotNull - Output will be non-null | |
// NotNull/When - Output will be non-null (when result == true/false) | |
// NotNull/If/NotNull - Output will be non-null (if argument == non-null) | |
// MemberNotNull - Method/property will ensure that the field/property is non-null | |
// MemberNotNull/When - Method/property will ensure that the field/property is non-null (when result == true/false) | |
// DoesNotReturn - Method will never return | |
// DoesNotReturn/If - Method will never return (if argument == true/false) | |
// Input | |
[AttributeUsage( AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false )] | |
public sealed class AllowNullAttribute : Attribute { | |
} | |
[AttributeUsage( AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false )] | |
public sealed class DisallowNullAttribute : Attribute { | |
} | |
// Output/MaybeNull | |
[AttributeUsage( AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false )] | |
public sealed class MaybeNullAttribute : Attribute { | |
} | |
[AttributeUsage( AttributeTargets.Parameter, Inherited = false )] | |
public sealed class MaybeNullWhenAttribute : Attribute { | |
public bool ReturnValue { get; } | |
public MaybeNullWhenAttribute(bool returnValue) { | |
ReturnValue = returnValue; | |
} | |
} | |
// Output/NotNull | |
[AttributeUsage( AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false )] | |
public sealed class NotNullAttribute : Attribute { | |
} | |
[AttributeUsage( AttributeTargets.Parameter, Inherited = false )] | |
public sealed class NotNullWhenAttribute : Attribute { | |
public bool ReturnValue { get; } | |
public NotNullWhenAttribute(bool returnValue) { | |
ReturnValue = returnValue; | |
} | |
} | |
[AttributeUsage( AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false )] | |
public sealed class NotNullIfNotNullAttribute : Attribute { | |
public string ParameterName { get; } | |
public NotNullIfNotNullAttribute(string parameterName) { | |
ParameterName = parameterName; | |
} | |
} | |
// Ensure | |
[AttributeUsage( AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true )] | |
public sealed class MemberNotNullAttribute : Attribute { | |
public string[] Members { get; } | |
public MemberNotNullAttribute(string member) { | |
Members = new[] { member }; | |
} | |
public MemberNotNullAttribute(params string[] members) { | |
Members = members; | |
} | |
} | |
[AttributeUsage( AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true )] | |
public sealed class MemberNotNullWhenAttribute : Attribute { | |
public bool ReturnValue { get; } | |
public string[] Members { get; } | |
public MemberNotNullWhenAttribute(bool returnValue, string member) { | |
ReturnValue = returnValue; | |
Members = new[] { member }; | |
} | |
public MemberNotNullWhenAttribute(bool returnValue, params string[] members) { | |
ReturnValue = returnValue; | |
Members = members; | |
} | |
} | |
// DoesNotReturn | |
[AttributeUsage( AttributeTargets.Method, Inherited = false )] | |
public sealed class DoesNotReturnAttribute : Attribute { | |
} | |
[AttributeUsage( AttributeTargets.Parameter, Inherited = false )] | |
public sealed class DoesNotReturnIfAttribute : Attribute { | |
public bool ParameterValue { get; } | |
public DoesNotReturnIfAttribute(bool parameterValue) { | |
ParameterValue = parameterValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment