From d6c16e00df44d5807972eea37e8b0d0bbf1e25f9 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Fri, 26 Mar 2021 23:29:41 -0500 Subject: [PATCH] Add System.Diagnostics.CodeAnalysis to common targets --- BSIPA.sln | 1 + Common.targets | 4 ++ System.Diagnostics.CodeAnalysis.cs | 76 ++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 System.Diagnostics.CodeAnalysis.cs diff --git a/BSIPA.sln b/BSIPA.sln index 1a4c85e7..f2a38632 100644 --- a/BSIPA.sln +++ b/BSIPA.sln @@ -24,6 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .github\workflows\docs.yml = .github\workflows\docs.yml README.md = README.md .github\release_draft.yml = .github\release_draft.yml + System.Diagnostics.CodeAnalysis.cs = System.Diagnostics.CodeAnalysis.cs .github\workflows\tag_docs.yml = .github\workflows\tag_docs.yml EndProjectSection EndProject diff --git a/Common.targets b/Common.targets index 07459379..56750be5 100644 --- a/Common.targets +++ b/Common.targets @@ -1,4 +1,8 @@  + + + + \ No newline at end of file diff --git a/System.Diagnostics.CodeAnalysis.cs b/System.Diagnostics.CodeAnalysis.cs new file mode 100644 index 00000000..cedced0f --- /dev/null +++ b/System.Diagnostics.CodeAnalysis.cs @@ -0,0 +1,76 @@ +#if !NETSTANDARD2_1 +namespace System.Diagnostics.CodeAnalysis +{ + // Effectively the Microsoft implementation for when it doesn't exist for my convenience + + /// + /// Specifies that when a method returns , + /// the parameter may be even if the corresponding type disallows it. + /// + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class MaybeNullWhenAttribute : Attribute + { + /// + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this + /// value, the associated parameter may be null. + public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// + /// Gets the return value condition. + /// + /// The return value condition. If the method returns this value, the + /// associated parameter may be null. + public bool ReturnValue { get; } + } + /// + /// Specifies that when a method returns , + /// the parameter is not even if the corresponding type allows it. + /// + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class NotNullWhenAttribute : Attribute + { + /// + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this + /// value, the associated parameter is not null. + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// + /// Gets the return value condition. + /// + /// The return value condition. If the method returns this value, the + /// associated parameter is not null. + public bool ReturnValue { get; } + } + /// + /// Specifies that an output may be even if the corresponding type disallows it. + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] + internal sealed class MaybeNullAttribute : Attribute + { + } + /// + /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. + /// + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class DoesNotReturnIfAttribute : Attribute + { + /// + /// Initializes the attribute with the specified parameter value. + /// + /// + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to + /// the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; + + /// + /// Gets the condition parameter value. + /// + public bool ParameterValue { get; } + } +} +#endif