From 1d115f457a690b7c8b127a75453c0a26991893b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=B6mer?= <30902964+manuelroemer@users.noreply.github.com> Date: Tue, 15 Sep 2020 15:00:26 +0200 Subject: [PATCH] Preparation for .NET 5 attributes (MemberNotNull, MemberNotNullWhen) and revamp of the project and how it is built. --- .nuke | 1 + build.ps1 | 31 -- build/.editorconfig | 11 + build/Build.cs | 99 ++++++ build/_build.csproj | 20 ++ .../NullableAttributes.cs | 316 ------------------ .../Nullable.NoExcludeFromCodeCoverage.csproj | 11 - .../NullableAttributes.cs | 316 ------------------ src/Nullable.nuspec | 156 +++++++-- src/Nullable.sln | 52 ++- src/Nullable/AllowNullAttribute.cs | 73 ++++ src/Nullable/DisallowNullAttribute.cs | 73 ++++ src/Nullable/DoesNotReturnAttribute.cs | 70 ++++ src/Nullable/DoesNotReturnIfAttribute.cs | 88 +++++ src/Nullable/MaybeNullAttribute.cs | 74 ++++ src/Nullable/MaybeNullWhenAttribute.cs | 85 +++++ src/Nullable/MemberNotNullAttribute.cs | 96 ++++++ src/Nullable/MemberNotNullWhenAttribute.cs | 114 +++++++ src/Nullable/NotNullAttribute.cs | 74 ++++ src/Nullable/NotNullIfNotNullAttribute.cs | 91 +++++ src/Nullable/NotNullWhenAttribute.cs | 85 +++++ .../Nullable.csproj} | 2 +- 22 files changed, 1208 insertions(+), 730 deletions(-) create mode 100644 .nuke delete mode 100644 build.ps1 create mode 100644 build/.editorconfig create mode 100644 build/Build.cs create mode 100644 build/_build.csproj delete mode 100644 src/Nullable.ExcludeFromCodeCoverage/NullableAttributes.cs delete mode 100644 src/Nullable.NoExcludeFromCodeCoverage/Nullable.NoExcludeFromCodeCoverage.csproj delete mode 100644 src/Nullable.NoExcludeFromCodeCoverage/NullableAttributes.cs create mode 100644 src/Nullable/AllowNullAttribute.cs create mode 100644 src/Nullable/DisallowNullAttribute.cs create mode 100644 src/Nullable/DoesNotReturnAttribute.cs create mode 100644 src/Nullable/DoesNotReturnIfAttribute.cs create mode 100644 src/Nullable/MaybeNullAttribute.cs create mode 100644 src/Nullable/MaybeNullWhenAttribute.cs create mode 100644 src/Nullable/MemberNotNullAttribute.cs create mode 100644 src/Nullable/MemberNotNullWhenAttribute.cs create mode 100644 src/Nullable/NotNullAttribute.cs create mode 100644 src/Nullable/NotNullIfNotNullAttribute.cs create mode 100644 src/Nullable/NotNullWhenAttribute.cs rename src/{Nullable.ExcludeFromCodeCoverage/Nullable.ExcludeFromCodeCoverage.csproj => Nullable/Nullable.csproj} (88%) diff --git a/.nuke b/.nuke new file mode 100644 index 0000000..c6084ff --- /dev/null +++ b/.nuke @@ -0,0 +1 @@ +src/Nullable.sln \ No newline at end of file diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index cfba027..0000000 --- a/build.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -Param( - [string] $artifactPath = "./artifacts", - [string] $srcPath = "./src" -) - -$nuspecPath = Join-Path $srcPath 'Nullable.nuspec' - -function Clean() { - Get-ChildItem $srcPath -Include *.pp -Recurse | Remove-Item -} - -# Clean before, so that there are no left-over files. -Clean - -# Ensure that the project builds. -dotnet restore $srcPath --ignore-failed-sources -dotnet build $srcPath --ignore-failed-sources - -if ($LASTEXITCODE -ne 0) { - throw "dotnet build failed with errors." -} - -# Rename the existing .cs files to .cs.pp. -# Doing this ensures that the files aren't listed in the solution explorer when the package -# is consumed via NuGet. With .cs files, that happens. -Get-ChildItem $srcPath -Include *.cs -Recurse | % { Copy-Item $_.FullName -Destination "$($_.FullName).pp" } - -# Package the .pp files. The configuration is done in the .nuspec. -nuget pack $nuspecPath -OutputDirectory $artifactPath - -Clean diff --git a/build/.editorconfig b/build/.editorconfig new file mode 100644 index 0000000..31e43dc --- /dev/null +++ b/build/.editorconfig @@ -0,0 +1,11 @@ +[*.cs] +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning +dotnet_style_require_accessibility_modifiers = never:warning + +csharp_style_expression_bodied_methods = true:silent +csharp_style_expression_bodied_properties = true:warning +csharp_style_expression_bodied_indexers = true:warning +csharp_style_expression_bodied_accessors = true:warning diff --git a/build/Build.cs b/build/Build.cs new file mode 100644 index 0000000..0adcff1 --- /dev/null +++ b/build/Build.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Nuke.Common; +using Nuke.Common.Execution; +using Nuke.Common.ProjectModel; +using Nuke.Common.Tooling; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.NuGet; +using static Nuke.Common.IO.FileSystemTasks; +using static Nuke.Common.Tools.DotNet.DotNetTasks; +using static Nuke.Common.Tools.NuGet.NuGetTasks; + +[CheckBuildProjectConfigurations] +[UnsetVisualStudioEnvironmentVariables] +class Build : NukeBuild +{ + public static int Main () => Execute(x => x.Pack); + + [Solution] readonly Solution Solution; + + Project NullableProject => Solution.GetProject("Nullable"); + + IEnumerable AttributeFiles => Directory + .GetFiles(NullableProject.Directory, "*Attribute.cs", SearchOption.AllDirectories) + .Select(path => new FileInfo(path)); + + FileInfo NuspecFile => new FileInfo(RootDirectory / "src" / "Nullable.nuspec"); + + DirectoryInfo ArtifactsDirectory => new DirectoryInfo(RootDirectory / "artifacts"); + + DirectoryInfo OutDirectory => new DirectoryInfo(TemporaryDirectory / "out"); + + DirectoryInfo ExcludeFromCodeCoverageOutDirectory => new DirectoryInfo(TemporaryDirectory / "out" / "ExcludeFromCodeCoverage"); + + DirectoryInfo NoExcludeFromCodeCoverageOutDirectory => new DirectoryInfo(TemporaryDirectory / "out" / "NoExcludeFromCodeCoverage"); + + Target Clean => _ => _ + .Executes(() => + { + DeleteDirectory(ArtifactsDirectory.FullName); + DeleteDirectory(ExcludeFromCodeCoverageOutDirectory.FullName); + DeleteDirectory(NoExcludeFromCodeCoverageOutDirectory.FullName); + }); + + Target Compile => _ => _ + .Executes(() => + { + // We build once to verify that the sources don't contain errors. + // Has no function apart from that since the build output is not used. + DotNetBuild(s => s + .SetProjectFile(NullableProject.Path) + .SetIgnoreFailedSources(true)); + }); + + Target CreateOutFiles => _ => _ + .DependsOn(Clean) + .DependsOn(Compile) + .Executes(() => + { + // Nullable uses the [ExcludeFromCodeCoverage] attribute. + // This is not available in certain target frameworks (e.g. .NET 2.0 and .NET Standard 1.0). + // For this reason, we remove that attribute from the source code. + // This results in two different file versions. These are temporarily stored in the output directories + // and then used by the nuspec accordingly. + ExcludeFromCodeCoverageOutDirectory.Create(); + NoExcludeFromCodeCoverageOutDirectory.Create(); + + foreach (var attributeFile in AttributeFiles) + { + attributeFile.CopyTo(Path.Combine(ExcludeFromCodeCoverageOutDirectory.FullName, attributeFile.Name)); + attributeFile.CopyTo(Path.Combine(NoExcludeFromCodeCoverageOutDirectory.FullName, attributeFile.Name)); + } + + foreach (var noExcludeFromCodeCoverageFile in NoExcludeFromCodeCoverageOutDirectory.GetFiles()) + { + var content = File.ReadAllText(noExcludeFromCodeCoverageFile.FullName); + content = content.Replace("ExcludeFromCodeCoverage, ", ""); + File.WriteAllText(noExcludeFromCodeCoverageFile.FullName, content); + } + + // Renaming the .cs files to .cs.pp ensures that the files aren't listed in VS's solution explorer + // when the package is consumed via NuGet. With .cs files, that happens. + foreach (var csFile in OutDirectory.GetFiles("*.cs", SearchOption.AllDirectories)) + { + csFile.MoveTo($"{csFile.FullName}.pp"); + } + }); + + Target Pack => _ => _ + .DependsOn(CreateOutFiles) + .Executes(() => + { + NuGetPack(s => s + .SetTargetPath(NuspecFile.FullName) + .SetBasePath(OutDirectory.FullName) + .SetOutputDirectory(ArtifactsDirectory.FullName)); + }); +} diff --git a/build/_build.csproj b/build/_build.csproj new file mode 100644 index 0000000..4272c29 --- /dev/null +++ b/build/_build.csproj @@ -0,0 +1,20 @@ + + + + Exe + netcoreapp3.1 + + CS0649;CS0169 + .. + ..\src + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/src/Nullable.ExcludeFromCodeCoverage/NullableAttributes.cs b/src/Nullable.ExcludeFromCodeCoverage/NullableAttributes.cs deleted file mode 100644 index ff75a58..0000000 --- a/src/Nullable.ExcludeFromCodeCoverage/NullableAttributes.cs +++ /dev/null @@ -1,316 +0,0 @@ -// -// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). -// Please see https://github.com/manuelroemer/Nullable for more information. -// -// IMPORTANT: -// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. -// Consider migrating to PackageReferences instead: -// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference -// Migrating brings the following benefits: -// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. -// * The added files are immutable and can therefore not be modified by coincidence. -// * Updating/Uninstalling the package will work flawlessly. -// - -#region License -// MIT License -// -// Copyright (c) 2019 Manuel Römer -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -#endregion - -#if !NULLABLE_ATTRIBUTES_DISABLE -#nullable enable -#pragma warning disable - -namespace System.Diagnostics.CodeAnalysis -{ - using global::System; - -#if DEBUG - /// - /// Specifies that is allowed as an input even if the - /// corresponding type disallows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class AllowNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public AllowNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that is disallowed as an input even if the - /// corresponding type allows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class DisallowNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public DisallowNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that a method that will never return under any circumstance. - /// -#endif - [AttributeUsage(AttributeTargets.Method, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class DoesNotReturnAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// - /// -#endif - public DoesNotReturnAttribute() { } - } - -#if DEBUG - /// - /// Specifies that the method will not return if the associated - /// parameter is passed the specified value. - /// -#endif - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class DoesNotReturnIfAttribute : Attribute - { -#if DEBUG - /// - /// Gets the condition parameter value. - /// Code after the method is considered unreachable by diagnostics if the argument - /// to the associated parameter matches this value. - /// -#endif - public bool ParameterValue { get; } - -#if DEBUG - /// - /// 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. - /// -#endif - public DoesNotReturnIfAttribute(bool parameterValue) - { - ParameterValue = parameterValue; - } - } - -#if DEBUG - /// - /// Specifies that an output may be even if the - /// corresponding type disallows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | - AttributeTargets.Property | AttributeTargets.ReturnValue, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class MaybeNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public MaybeNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that when a method returns , - /// the parameter may be even if the corresponding type disallows it. - /// -#endif - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class MaybeNullWhenAttribute : Attribute - { -#if DEBUG - /// - /// Gets the return value condition. - /// If the method returns this value, the associated parameter may be . - /// -#endif - public bool ReturnValue { get; } - -#if DEBUG - /// - /// Initializes the attribute with the specified return value condition. - /// - /// - /// The return value condition. - /// If the method returns this value, the associated parameter may be . - /// -#endif - public MaybeNullWhenAttribute(bool returnValue) - { - ReturnValue = returnValue; - } - } - -#if DEBUG - /// - /// Specifies that an output is not even if the - /// corresponding type allows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | - AttributeTargets.Property | AttributeTargets.ReturnValue, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class NotNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public NotNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that the output will be non- if the - /// named parameter is non-. - /// -#endif - [AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, - AllowMultiple = true, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class NotNullIfNotNullAttribute : Attribute - { -#if DEBUG - /// - /// Gets the associated parameter name. - /// The output will be non- if the argument to the - /// parameter specified is non-. - /// -#endif - public string ParameterName { get; } - -#if DEBUG - /// - /// 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-. - /// -#endif - 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; - } - } - -#if DEBUG - /// - /// Specifies that when a method returns , - /// the parameter will not be even if the corresponding type allows it. - /// -#endif - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [ExcludeFromCodeCoverage, DebuggerNonUserCode] -#endif - internal sealed class NotNullWhenAttribute : Attribute - { -#if DEBUG - /// - /// Gets the return value condition. - /// If the method returns this value, the associated parameter will not be . - /// -#endif - public bool ReturnValue { get; } - -#if DEBUG - /// - /// 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 . - /// -#endif - public NotNullWhenAttribute(bool returnValue) - { - ReturnValue = returnValue; - } - } -} - -#pragma warning enable -#nullable restore -#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable.NoExcludeFromCodeCoverage/Nullable.NoExcludeFromCodeCoverage.csproj b/src/Nullable.NoExcludeFromCodeCoverage/Nullable.NoExcludeFromCodeCoverage.csproj deleted file mode 100644 index 65d65e2..0000000 --- a/src/Nullable.NoExcludeFromCodeCoverage/Nullable.NoExcludeFromCodeCoverage.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - netstandard1.0 - 8.0 - enable - System.Diagnostics.CodeAnalysis - true - - - diff --git a/src/Nullable.NoExcludeFromCodeCoverage/NullableAttributes.cs b/src/Nullable.NoExcludeFromCodeCoverage/NullableAttributes.cs deleted file mode 100644 index b75b6b1..0000000 --- a/src/Nullable.NoExcludeFromCodeCoverage/NullableAttributes.cs +++ /dev/null @@ -1,316 +0,0 @@ -// -// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). -// Please see https://github.com/manuelroemer/Nullable for more information. -// -// IMPORTANT: -// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. -// Consider migrating to PackageReferences instead: -// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference -// Migrating brings the following benefits: -// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. -// * The added files are immutable and can therefore not be modified by coincidence. -// * Updating/Uninstalling the package will work flawlessly. -// - -#region License -// MIT License -// -// Copyright (c) 2019 Manuel Römer -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -#endregion - -#if !NULLABLE_ATTRIBUTES_DISABLE -#nullable enable -#pragma warning disable - -namespace System.Diagnostics.CodeAnalysis -{ - using global::System; - -#if DEBUG - /// - /// Specifies that is allowed as an input even if the - /// corresponding type disallows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class AllowNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public AllowNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that is disallowed as an input even if the - /// corresponding type allows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class DisallowNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public DisallowNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that a method that will never return under any circumstance. - /// -#endif - [AttributeUsage(AttributeTargets.Method, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class DoesNotReturnAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// - /// -#endif - public DoesNotReturnAttribute() { } - } - -#if DEBUG - /// - /// Specifies that the method will not return if the associated - /// parameter is passed the specified value. - /// -#endif - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class DoesNotReturnIfAttribute : Attribute - { -#if DEBUG - /// - /// Gets the condition parameter value. - /// Code after the method is considered unreachable by diagnostics if the argument - /// to the associated parameter matches this value. - /// -#endif - public bool ParameterValue { get; } - -#if DEBUG - /// - /// 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. - /// -#endif - public DoesNotReturnIfAttribute(bool parameterValue) - { - ParameterValue = parameterValue; - } - } - -#if DEBUG - /// - /// Specifies that an output may be even if the - /// corresponding type disallows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | - AttributeTargets.Property | AttributeTargets.ReturnValue, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class MaybeNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public MaybeNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that when a method returns , - /// the parameter may be even if the corresponding type disallows it. - /// -#endif - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class MaybeNullWhenAttribute : Attribute - { -#if DEBUG - /// - /// Gets the return value condition. - /// If the method returns this value, the associated parameter may be . - /// -#endif - public bool ReturnValue { get; } - -#if DEBUG - /// - /// Initializes the attribute with the specified return value condition. - /// - /// - /// The return value condition. - /// If the method returns this value, the associated parameter may be . - /// -#endif - public MaybeNullWhenAttribute(bool returnValue) - { - ReturnValue = returnValue; - } - } - -#if DEBUG - /// - /// Specifies that an output is not even if the - /// corresponding type allows it. - /// -#endif - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Parameter | - AttributeTargets.Property | AttributeTargets.ReturnValue, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class NotNullAttribute : Attribute - { -#if DEBUG - /// - /// Initializes a new instance of the class. - /// -#endif - public NotNullAttribute() { } - } - -#if DEBUG - /// - /// Specifies that the output will be non- if the - /// named parameter is non-. - /// -#endif - [AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, - AllowMultiple = true, - Inherited = false - )] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class NotNullIfNotNullAttribute : Attribute - { -#if DEBUG - /// - /// Gets the associated parameter name. - /// The output will be non- if the argument to the - /// parameter specified is non-. - /// -#endif - public string ParameterName { get; } - -#if DEBUG - /// - /// 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-. - /// -#endif - 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; - } - } - -#if DEBUG - /// - /// Specifies that when a method returns , - /// the parameter will not be even if the corresponding type allows it. - /// -#endif - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE - [DebuggerNonUserCode] -#endif - internal sealed class NotNullWhenAttribute : Attribute - { -#if DEBUG - /// - /// Gets the return value condition. - /// If the method returns this value, the associated parameter will not be . - /// -#endif - public bool ReturnValue { get; } - -#if DEBUG - /// - /// 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 . - /// -#endif - public NotNullWhenAttribute(bool returnValue) - { - ReturnValue = returnValue; - } - } -} - -#pragma warning enable -#nullable restore -#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable.nuspec b/src/Nullable.nuspec index 2cd2175..c8c9d3b 100644 --- a/src/Nullable.nuspec +++ b/src/Nullable.nuspec @@ -2,7 +2,7 @@ Nullable - 1.2.1 + 1.3.0-preview1 true Manuel Römer MIT @@ -10,16 +10,16 @@ https://github.com/manuelroemer/Nullable -A source code only package which allows you to use .NET Core 3.0's new nullable attributes in older target frameworks like .NET Standard 2.0 or the "old" .NET Framework. +A source code only package which allows you to use .NET's new nullable attributes in older target frameworks like .NET Standard 2.0 or the "old" .NET Framework. -This package does not contain any compiled binaries, but instead adds a single C# file with the attribute classes to your project. Because this C# file gets compiled together with the rest of your code, the built binaries will not have a dependency on this package, meaning that you can perfectly use it for both libraries and applications. +This package does not contain any compiled binaries, but instead adds the attribute classes as C# source code to your project. Because this code is compiled together with the rest of your code, the built binaries will not have a dependency on this package, meaning that you can perfectly use it for both libraries and applications. -The C# file is only included if you are targeting a framework version which does not support the new nullable attributes. For example, if you create a library which multi-targets .NET Standard 2.0 and 2.1, the file is only included in the .NET Standard 2.0 version, because .NET Standard 2.1 already provides the nullable attributes by default. +The C# code is only included if you are targeting a framework version which does not support the new nullable attributes. For example, if you create a library which multi-targets .NET Standard 2.0 and 2.1, the majority of the attributes are not included in the .NET Standard 2.1 version, because it already provides these by default. Please see https://github.com/manuelroemer/Nullable for additional information on how to use this package. https://github.com/manuelroemer/Nullable/blob/master/CHANGELOG.md - source compiletime csharp8.0 netcore3.0 null nullable attributes allownull disallownull doesnotreturn doesnotreturnif maybenull maybenullwhen notnull notnullifnotnull notnullwhen + source compiletime null nullable attributes allownull disallownull doesnotreturn doesnotreturnif maybenull maybenullwhen notnull notnullifnotnull notnullwhen membernotnull membernotnullwhen icon.png @@ -27,36 +27,136 @@ Please see https://github.com/manuelroemer/Nullable for additional information o - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + - - - - - - - + + diff --git a/src/Nullable.sln b/src/Nullable.sln index 3770cc5..0ffbe96 100644 --- a/src/Nullable.sln +++ b/src/Nullable.sln @@ -5,13 +5,12 @@ VisualStudioVersion = 16.0.29318.209 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Config", ".Config", "{CA94F8B9-B786-4737-B21A-FD4D2AE5D9E0}" ProjectSection(SolutionItems) = preProject - ..\build.ps1 = ..\build.ps1 Nullable.nuspec = Nullable.nuspec EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullable.ExcludeFromCodeCoverage", "Nullable.ExcludeFromCodeCoverage\Nullable.ExcludeFromCodeCoverage.csproj", "{AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "..\build\_build.csproj", "{012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullable.NoExcludeFromCodeCoverage", "Nullable.NoExcludeFromCodeCoverage\Nullable.NoExcludeFromCodeCoverage.csproj", "{F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nullable", "Nullable\Nullable.csproj", "{AF81D675-8017-44AF-841F-74D4EC7C083B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -23,30 +22,29 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Debug|x64.ActiveCfg = Debug|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Debug|x64.Build.0 = Debug|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Debug|x86.ActiveCfg = Debug|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Debug|x86.Build.0 = Debug|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Release|Any CPU.Build.0 = Release|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Release|x64.ActiveCfg = Release|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Release|x64.Build.0 = Release|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Release|x86.ActiveCfg = Release|Any CPU - {AFA70C9B-6FA2-4CF7-8DB2-744E8C10D1C8}.Release|x86.Build.0 = Release|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Debug|x64.ActiveCfg = Debug|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Debug|x64.Build.0 = Debug|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Debug|x86.ActiveCfg = Debug|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Debug|x86.Build.0 = Debug|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Release|Any CPU.Build.0 = Release|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Release|x64.ActiveCfg = Release|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Release|x64.Build.0 = Release|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Release|x86.ActiveCfg = Release|Any CPU - {F9CEC7D5-3C05-4EA4-B074-961E7BF57FB2}.Release|x86.Build.0 = Release|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Debug|x64.ActiveCfg = Debug|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Debug|x64.Build.0 = Debug|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Debug|x86.ActiveCfg = Debug|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Debug|x86.Build.0 = Debug|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Release|x64.ActiveCfg = Release|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Release|x64.Build.0 = Release|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Release|x86.ActiveCfg = Release|Any CPU + {012F7F51-BEC6-4FCC-BF9A-87BDECFAEDC4}.Release|x86.Build.0 = Release|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Debug|x64.ActiveCfg = Debug|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Debug|x64.Build.0 = Debug|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Debug|x86.ActiveCfg = Debug|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Debug|x86.Build.0 = Debug|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Release|Any CPU.Build.0 = Release|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Release|x64.ActiveCfg = Release|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Release|x64.Build.0 = Release|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Release|x86.ActiveCfg = Release|Any CPU + {AF81D675-8017-44AF-841F-74D4EC7C083B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Nullable/AllowNullAttribute.cs b/src/Nullable/AllowNullAttribute.cs new file mode 100644 index 0000000..2e053c9 --- /dev/null +++ b/src/Nullable/AllowNullAttribute.cs @@ -0,0 +1,73 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that is allowed as an input even if the + /// corresponding type disallows it. + /// +#endif + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false + )] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class AllowNullAttribute : Attribute + { +#if DEBUG + /// + /// Initializes a new instance of the class. + /// +#endif + public AllowNullAttribute() { } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/DisallowNullAttribute.cs b/src/Nullable/DisallowNullAttribute.cs new file mode 100644 index 0000000..339642d --- /dev/null +++ b/src/Nullable/DisallowNullAttribute.cs @@ -0,0 +1,73 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that is disallowed as an input even if the + /// corresponding type allows it. + /// +#endif + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, + Inherited = false + )] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class DisallowNullAttribute : Attribute + { +#if DEBUG + /// + /// Initializes a new instance of the class. + /// +#endif + public DisallowNullAttribute() { } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/DoesNotReturnAttribute.cs b/src/Nullable/DoesNotReturnAttribute.cs new file mode 100644 index 0000000..9bdef9e --- /dev/null +++ b/src/Nullable/DoesNotReturnAttribute.cs @@ -0,0 +1,70 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that a method that will never return under any circumstance. + /// +#endif + [AttributeUsage(AttributeTargets.Method, Inherited = false)] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class DoesNotReturnAttribute : Attribute + { +#if DEBUG + /// + /// Initializes a new instance of the class. + /// + /// +#endif + public DoesNotReturnAttribute() { } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/DoesNotReturnIfAttribute.cs b/src/Nullable/DoesNotReturnIfAttribute.cs new file mode 100644 index 0000000..bc98b92 --- /dev/null +++ b/src/Nullable/DoesNotReturnIfAttribute.cs @@ -0,0 +1,88 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that the method will not return if the associated + /// parameter is passed the specified value. + /// +#endif + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class DoesNotReturnIfAttribute : Attribute + { +#if DEBUG + /// + /// Gets the condition parameter value. + /// Code after the method is considered unreachable by diagnostics if the argument + /// to the associated parameter matches this value. + /// +#endif + public bool ParameterValue { get; } + +#if DEBUG + /// + /// 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. + /// +#endif + public DoesNotReturnIfAttribute(bool parameterValue) + { + ParameterValue = parameterValue; + } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/MaybeNullAttribute.cs b/src/Nullable/MaybeNullAttribute.cs new file mode 100644 index 0000000..7037888 --- /dev/null +++ b/src/Nullable/MaybeNullAttribute.cs @@ -0,0 +1,74 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that an output may be even if the + /// corresponding type disallows it. + /// +#endif + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.Parameter | + AttributeTargets.Property | AttributeTargets.ReturnValue, + Inherited = false + )] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class MaybeNullAttribute : Attribute + { +#if DEBUG + /// + /// Initializes a new instance of the class. + /// +#endif + public MaybeNullAttribute() { } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/MaybeNullWhenAttribute.cs b/src/Nullable/MaybeNullWhenAttribute.cs new file mode 100644 index 0000000..dd221d8 --- /dev/null +++ b/src/Nullable/MaybeNullWhenAttribute.cs @@ -0,0 +1,85 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that when a method returns , + /// the parameter may be even if the corresponding type disallows it. + /// +#endif + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class MaybeNullWhenAttribute : Attribute + { +#if DEBUG + /// + /// Gets the return value condition. + /// If the method returns this value, the associated parameter may be . + /// +#endif + public bool ReturnValue { get; } + +#if DEBUG + /// + /// Initializes the attribute with the specified return value condition. + /// + /// + /// The return value condition. + /// If the method returns this value, the associated parameter may be . + /// +#endif + public MaybeNullWhenAttribute(bool returnValue) + { + ReturnValue = returnValue; + } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/MemberNotNullAttribute.cs b/src/Nullable/MemberNotNullAttribute.cs new file mode 100644 index 0000000..b843e78 --- /dev/null +++ b/src/Nullable/MemberNotNullAttribute.cs @@ -0,0 +1,96 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that the method or property will ensure that the listed field and property members have + /// not- values. + /// +#endif + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class MemberNotNullAttribute : Attribute + { +#if DEBUG + /// + /// Gets field or property member names. + /// +#endif + public string[] Members { get; } + +#if DEBUG + /// + /// Initializes the attribute with a field or property member. + /// + /// + /// The field or property member that is promised to be not-null. + /// +#endif + public MemberNotNullAttribute(string member) + { + Members = new[] { member }; + } + +#if DEBUG + /// + /// Initializes the attribute with the list of field and property members. + /// + /// + /// The list of field and property members that are promised to be not-null. + /// +#endif + public MemberNotNullAttribute(params string[] members) + { + Members = members; + } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/MemberNotNullWhenAttribute.cs b/src/Nullable/MemberNotNullWhenAttribute.cs new file mode 100644 index 0000000..fdf0e5f --- /dev/null +++ b/src/Nullable/MemberNotNullWhenAttribute.cs @@ -0,0 +1,114 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that the method or property will ensure that the listed field and property members have + /// non- values when returning with the specified return value condition. + /// +#endif + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class MemberNotNullWhenAttribute : Attribute + { +#if DEBUG + /// + /// Gets the return value condition. + /// +#endif + public bool ReturnValue { get; } + +#if DEBUG + /// + /// Gets field or property member names. + /// +#endif + public string[] Members { get; } + +#if DEBUG + /// + /// Initializes the attribute with the specified return value condition and a field or property member. + /// + /// + /// The return value condition. If the method returns this value, + /// the associated parameter will not be . + /// + /// + /// The field or property member that is promised to be not-. + /// +#endif + public MemberNotNullWhenAttribute(bool returnValue, string member) + { + ReturnValue = returnValue; + Members = new[] { member }; + } + +#if DEBUG + /// + /// Initializes the attribute with the specified return value condition and list + /// of field and property members. + /// + /// + /// The return value condition. If the method returns this value, + /// the associated parameter will not be . + /// + /// + /// The list of field and property members that are promised to be not-null. + /// +#endif + public MemberNotNullWhenAttribute(bool returnValue, params string[] members) + { + ReturnValue = returnValue; + Members = members; + } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/NotNullAttribute.cs b/src/Nullable/NotNullAttribute.cs new file mode 100644 index 0000000..fae5061 --- /dev/null +++ b/src/Nullable/NotNullAttribute.cs @@ -0,0 +1,74 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that an output is not even if the + /// corresponding type allows it. + /// +#endif + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.Parameter | + AttributeTargets.Property | AttributeTargets.ReturnValue, + Inherited = false + )] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class NotNullAttribute : Attribute + { +#if DEBUG + /// + /// Initializes a new instance of the class. + /// +#endif + public NotNullAttribute() { } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/NotNullIfNotNullAttribute.cs b/src/Nullable/NotNullIfNotNullAttribute.cs new file mode 100644 index 0000000..796ac15 --- /dev/null +++ b/src/Nullable/NotNullIfNotNullAttribute.cs @@ -0,0 +1,91 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that the output will be non- if the + /// named parameter is non-. + /// +#endif + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, + AllowMultiple = true, + Inherited = false + )] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class NotNullIfNotNullAttribute : Attribute + { +#if DEBUG + /// + /// Gets the associated parameter name. + /// The output will be non- if the argument to the + /// parameter specified is non-. + /// +#endif + public string ParameterName { get; } + +#if DEBUG + /// + /// 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-. + /// +#endif + public NotNullIfNotNullAttribute(string parameterName) + { + ParameterName = parameterName; + } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable/NotNullWhenAttribute.cs b/src/Nullable/NotNullWhenAttribute.cs new file mode 100644 index 0000000..578d439 --- /dev/null +++ b/src/Nullable/NotNullWhenAttribute.cs @@ -0,0 +1,85 @@ +// +// This code file has automatically been added by the "Nullable" NuGet package (https://www.nuget.org/packages/Nullable). +// Please see https://github.com/manuelroemer/Nullable for more information. +// +// IMPORTANT: +// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references. +// Consider migrating to PackageReferences instead: +// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference +// Migrating brings the following benefits: +// * The "Nullable" folder and the "NullableAttributes.cs" files don't appear in your project. +// * The added files are immutable and can therefore not be modified by coincidence. +// * Updating/Uninstalling the package will work flawlessly. +// + +#region License +// MIT License +// +// Copyright (c) Manuel Römer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#endregion + +#if !NULLABLE_ATTRIBUTES_DISABLE +#nullable enable +#pragma warning disable + +namespace System.Diagnostics.CodeAnalysis +{ + using global::System; + +#if DEBUG + /// + /// Specifies that when a method returns , + /// the parameter will not be even if the corresponding type allows it. + /// +#endif + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if !NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE + [ExcludeFromCodeCoverage, DebuggerNonUserCode] +#endif + internal sealed class NotNullWhenAttribute : Attribute + { +#if DEBUG + /// + /// Gets the return value condition. + /// If the method returns this value, the associated parameter will not be . + /// +#endif + public bool ReturnValue { get; } + +#if DEBUG + /// + /// 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 . + /// +#endif + public NotNullWhenAttribute(bool returnValue) + { + ReturnValue = returnValue; + } + } +} + +#pragma warning enable +#nullable restore +#endif // NULLABLE_ATTRIBUTES_DISABLE diff --git a/src/Nullable.ExcludeFromCodeCoverage/Nullable.ExcludeFromCodeCoverage.csproj b/src/Nullable/Nullable.csproj similarity index 88% rename from src/Nullable.ExcludeFromCodeCoverage/Nullable.ExcludeFromCodeCoverage.csproj rename to src/Nullable/Nullable.csproj index aa8364b..a1536f9 100644 --- a/src/Nullable.ExcludeFromCodeCoverage/Nullable.ExcludeFromCodeCoverage.csproj +++ b/src/Nullable/Nullable.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 8.0 + preview enable System.Diagnostics.CodeAnalysis true