#if !NETSTANDARD2_1
namespace System.Diagnostics.CodeAnalysis
{
using System;
///
/// Specifies that is allowed as an input even if the
/// corresponding type disallows it.
///
[AttributeUsage(
AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property,
Inherited = false
)]
[ExcludeFromCodeCoverage]
internal sealed class AllowNullAttribute : Attribute
{
///
/// Initializes a new instance of the class.
///
public AllowNullAttribute() { }
}
///
/// Specifies that is disallowed as an input even if the
/// corresponding type allows it.
///
[AttributeUsage(
AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property,
Inherited = false
)]
[ExcludeFromCodeCoverage]
internal sealed class DisallowNullAttribute : Attribute
{
///
/// Initializes a new instance of the class.
///
public DisallowNullAttribute() { }
}
///
/// Specifies that a method that will never return under any circumstance.
///
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class DoesNotReturnAttribute : Attribute
{
///
/// Initializes a new instance of the class.
///
public DoesNotReturnAttribute() { }
}
///
/// Specifies that the method will not return if the associated
/// parameter is passed the specified value.
///
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class DoesNotReturnIfAttribute : Attribute
{
///
/// Gets the condition parameter value.
/// Code after the method is considered unreachable by diagnostics if the argument
/// to the associated parameter matches this value.
///
public bool ParameterValue { get; }
///
/// Initializes a new instance of the
/// class with the specified parameter value.
///
///
/// The condition parameter value.
/// Code after the method is considered unreachable by diagnostics if the argument
/// to the associated parameter matches this value.
///
public DoesNotReturnIfAttribute(bool parameterValue)
{
ParameterValue = parameterValue;
}
}
///
/// Specifies that an output may be even if the
/// corresponding type disallows it.
///
[AttributeUsage(
AttributeTargets.Field | AttributeTargets.Parameter |
AttributeTargets.Property | AttributeTargets.ReturnValue,
Inherited = false
)]
[ExcludeFromCodeCoverage]
internal sealed class MaybeNullAttribute : Attribute
{
///
/// Initializes a new instance of the class.
///
public MaybeNullAttribute() { }
}
///
/// Specifies that when a method returns ,
/// the parameter may be even if the corresponding type disallows it.
///
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class MaybeNullWhenAttribute : Attribute
{
///
/// Gets the return value condition.
/// If the method returns this value, the associated parameter may be .
///
public bool ReturnValue { get; }
///
/// Initializes the attribute with the specified return value condition.
///
///
/// The return value condition.
/// If the method returns this value, the associated parameter may be .
///
public MaybeNullWhenAttribute(bool returnValue)
{
ReturnValue = returnValue;
}
}
///
/// Specifies that an output is not even if the
/// corresponding type allows it.
///
[AttributeUsage(
AttributeTargets.Field | AttributeTargets.Parameter |
AttributeTargets.Property | AttributeTargets.ReturnValue,
Inherited = false
)]
[ExcludeFromCodeCoverage]
internal sealed class NotNullAttribute : Attribute
{
///
/// Initializes a new instance of the class.
///
public NotNullAttribute() { }
}
///
/// Specifies that the output will be non- if the
/// named parameter is non-.
///
[AttributeUsage(
AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue,
AllowMultiple = true,
Inherited = false
)]
[ExcludeFromCodeCoverage]
internal sealed class NotNullIfNotNullAttribute : Attribute
{
///
/// Gets the associated parameter name.
/// The output will be non- if the argument to the
/// parameter specified is non-.
///
public string ParameterName { get; }
///
/// Initializes the attribute with the associated parameter name.
///
///
/// The associated parameter name.
/// The output will be non- if the argument to the
/// parameter specified is non-.
///
public NotNullIfNotNullAttribute(string parameterName)
{
// .NET Core 3.0 doesn't throw an ArgumentNullException, even though this is
// tagged as non-null.
// Follow this behavior here.
ParameterName = parameterName;
}
}
///
/// Specifies that when a method returns ,
/// the parameter will not be even if the corresponding type allows it.
///
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class NotNullWhenAttribute : Attribute
{
///
/// Gets the return value condition.
/// If the method returns this value, the associated parameter will not be .
///
public bool ReturnValue { get; }
///
/// Initializes the attribute with the specified return value condition.
///
///
/// The return value condition.
/// If the method returns this value, the associated parameter will not be .
///
public NotNullWhenAttribute(bool returnValue)
{
ReturnValue = returnValue;
}
}
}
#endif