From a8b207f0758bdd13b9dc1d96b5a73e8a8f07f781 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Fri, 5 Apr 2024 13:42:38 +0200 Subject: [PATCH] #124 added missing nullable attributes from net6-8 --- .../CodeAnalysis/AllowNullAttribute.cs | 35 +++++++++++ .../CallerArgumentExpressionAttribute.cs | 37 +++++++++++ .../CompilerFeatureRequiredAttribute.cs | 56 +++++++++++++++++ .../CodeAnalysis/DisallowNullAttribute.cs | 34 ++++++++++ .../CodeAnalysis/DoesNotReturnAttribute.cs | 35 +++++++++++ .../CodeAnalysis/DoesNotReturnIfAttribute.cs | 49 +++++++++++++++ .../CodeAnalysis/IsExternalInit.cs | 29 +++++++++ .../CodeAnalysis/MaybeNullAttribute.cs | 10 +++ .../CodeAnalysis/MaybeNullWhenAttribute.cs | 22 +++++++ .../CodeAnalysis/MemberNotNullAttribute.cs | 49 +++++++++++++++ .../MemberNotNullWhenAttribute.cs | 62 +++++++++++++++++++ .../CodeAnalysis/NotNullAttribute.cs | 30 +++++++++ .../NotNullIfNotNullAttribute.cs | 6 +- .../CodeAnalysis/NotNullWhenAttribute.cs | 43 +++++++++++++ .../CodeAnalysis/NullableAttribute.cs | 39 ++++++++++++ .../CodeAnalysis/NullableContextAttribute.cs | 36 +++++++++++ .../CodeAnalysis/RequiredMemberAttribute.cs | 29 +++++++++ .../SetsRequiredMembersAttribute.cs | 30 +++++++++ .../CodeAnalysis/ValidatedNotNullAttribute.cs | 29 +++++++++ 19 files changed, 657 insertions(+), 3 deletions(-) create mode 100644 src/log4net/Diagnostics/CodeAnalysis/AllowNullAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/CallerArgumentExpressionAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/CompilerFeatureRequiredAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/DisallowNullAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnIfAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/IsExternalInit.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/MaybeNullAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/MaybeNullWhenAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/MemberNotNullAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/MemberNotNullWhenAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/NotNullAttribute.cs rename src/log4net/{Util => Diagnostics/CodeAnalysis}/NotNullIfNotNullAttribute.cs (95%) create mode 100644 src/log4net/Diagnostics/CodeAnalysis/NotNullWhenAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/NullableAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/NullableContextAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/RequiredMemberAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/SetsRequiredMembersAttribute.cs create mode 100644 src/log4net/Diagnostics/CodeAnalysis/ValidatedNotNullAttribute.cs diff --git a/src/log4net/Diagnostics/CodeAnalysis/AllowNullAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/AllowNullAttribute.cs new file mode 100644 index 00000000..4d738601 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/AllowNullAttribute.cs @@ -0,0 +1,35 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that null is allowed as an input even if the corresponding type disallows it. +/// +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)] +internal sealed class AllowNullAttribute : Attribute +{ + /// + /// Initializes a new instance of the System.Diagnostics.CodeAnalysis.AllowNullAttribute class. + /// + public AllowNullAttribute() + { } +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/CallerArgumentExpressionAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/CallerArgumentExpressionAttribute.cs new file mode 100644 index 00000000..3533cfd5 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/CallerArgumentExpressionAttribute.cs @@ -0,0 +1,37 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Runtime.CompilerServices; + +/// +/// Indicates that a parameter captures the expression passed for another parameter as a string. +/// +[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +internal sealed class CallerArgumentExpressionAttribute : Attribute +{ + /// + /// Name of the parameter whose expression should be captured as a string + /// + public string ParameterName { get; } + + /// + public CallerArgumentExpressionAttribute(string parameterName) => ParameterName = parameterName; +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/CompilerFeatureRequiredAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/CompilerFeatureRequiredAttribute.cs new file mode 100644 index 00000000..7ccc60c1 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/CompilerFeatureRequiredAttribute.cs @@ -0,0 +1,56 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET7_0_OR_GREATER +namespace System.Runtime.CompilerServices; + +/// +/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied +/// +[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)] +internal sealed class CompilerFeatureRequiredAttribute : Attribute +{ + /// + /// The used for the ref structs C# feature + /// + public const string RefStructs = nameof(RefStructs); + + /// + /// The used for the required members C# feature + /// + public const string RequiredMembers = nameof(RequiredMembers); + + /// + /// The name of the compiler feature + /// + public string FeatureName { get; } + + /// + /// Gets a value that indicates whether the compiler can choose to allow access to the location + /// where this attribute is applied if it does not understand + /// + public bool IsOptional { get; init; } + + /// + /// Initializes a instance for the passed in compiler feature + /// + /// The name of the compiler feature + public CompilerFeatureRequiredAttribute(string featureName) => FeatureName = featureName; +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/DisallowNullAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/DisallowNullAttribute.cs new file mode 100644 index 00000000..4cd0bee3 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/DisallowNullAttribute.cs @@ -0,0 +1,34 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that null is disallowed as an input even if the corresponding type allows it. +/// +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)] +internal sealed class DisallowNullAttribute : Attribute +{ + /// + /// Initializes a new instance of the System.Diagnostics.CodeAnalysis.DisallowNullAttribute class. + /// + public DisallowNullAttribute() { } +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnAttribute.cs new file mode 100644 index 00000000..800a0eda --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnAttribute.cs @@ -0,0 +1,35 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that a method that will never return under any circumstance. +/// +[AttributeUsage(AttributeTargets.Method, Inherited = false)] +internal sealed class DoesNotReturnAttribute : Attribute +{ + /// + /// Initializes a new instance of the System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute class. + /// + public DoesNotReturnAttribute() + { } +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnIfAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnIfAttribute.cs new file mode 100644 index 00000000..520559b8 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/DoesNotReturnIfAttribute.cs @@ -0,0 +1,49 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that the method will not return if the associated System.Boolean parameter is passed the specified value. +/// +[AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +internal sealed class DoesNotReturnIfAttribute : Attribute +{ + /// + /// Initializes a new instance of the System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute 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; + + /// + /// Gets the condition 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 bool ParameterValue { get; } +} + +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/IsExternalInit.cs b/src/log4net/Diagnostics/CodeAnalysis/IsExternalInit.cs new file mode 100644 index 00000000..20f890f5 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/IsExternalInit.cs @@ -0,0 +1,29 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +using System.ComponentModel; + +namespace System.Runtime.CompilerServices; + +/// +[EditorBrowsable(EditorBrowsableState.Never)] +internal static class IsExternalInit +{ } +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/MaybeNullAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/MaybeNullAttribute.cs new file mode 100644 index 00000000..974e0a1f --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/MaybeNullAttribute.cs @@ -0,0 +1,10 @@ +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that an output may be null even if the corresponding type disallows it. +/// +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)] +internal sealed class MaybeNullAttribute : Attribute +{ } +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/MaybeNullWhenAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/MaybeNullWhenAttribute.cs new file mode 100644 index 00000000..6038ae9d --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/MaybeNullWhenAttribute.cs @@ -0,0 +1,22 @@ +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that when a method returns System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.ReturnValue, +/// the parameter may be null 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. + /// + public bool ReturnValue { get; } +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/MemberNotNullAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/MemberNotNullAttribute.cs new file mode 100644 index 00000000..728ed612 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/MemberNotNullAttribute.cs @@ -0,0 +1,49 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that the method or property will ensure that the listed field and property members have values that aren't null. +/// +[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] +internal sealed class MemberNotNullAttribute : Attribute +{ + /// + /// Initializes the attribute with list of field or property members. + /// + /// The list of field and property members that are promised to be non-null. + public MemberNotNullAttribute(params string[] members) => Members = members; + + /// + /// Initializes the attribute with a field or property member. + /// + /// The field or property member that is promised to be non-null. + [SuppressMessage("Design", "CA1019:Define accessors for attribute arguments", Justification = "LuGe: 1-zu-1 von DotNet geklaut")] + public MemberNotNullAttribute(string member) + : this(new[] { member }) + { } + + /// + /// Gets field or property member names. + /// + public string[] Members { get; } +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/MemberNotNullWhenAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/MemberNotNullWhenAttribute.cs new file mode 100644 index 00000000..6234bc3c --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/MemberNotNullWhenAttribute.cs @@ -0,0 +1,62 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that the method or property will ensure that the listed field and property members have non-null values +/// when returning with the specified return value condition. +/// +[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] +internal sealed class MemberNotNullWhenAttribute : Attribute +{ + /// + /// 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 null. + /// The list of field and property members that are promised to be non-null. + [SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] + public MemberNotNullWhenAttribute(bool returnValue, params string[] members) + { + ReturnValue = returnValue; + Members = members; + } + + /// + /// 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 null. + /// The field or property member that is promised to be non-null. + [SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] + public MemberNotNullWhenAttribute(bool returnValue, string member) + : this(returnValue, new[] { member }) + { } + + /// + /// Gets field or property member names. + /// + public string[] Members { get; } + + /// + /// Gets the return value condition. + /// + public bool ReturnValue { get; } +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/NotNullAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/NotNullAttribute.cs new file mode 100644 index 00000000..7199d4b5 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/NotNullAttribute.cs @@ -0,0 +1,30 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that an output is not even if the corresponding type allows it. +/// Specifies that an input argument was not when the call returns. +/// +[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] +internal sealed class NotNullAttribute : Attribute +{ } +#endif \ No newline at end of file diff --git a/src/log4net/Util/NotNullIfNotNullAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/NotNullIfNotNullAttribute.cs similarity index 95% rename from src/log4net/Util/NotNullIfNotNullAttribute.cs rename to src/log4net/Diagnostics/CodeAnalysis/NotNullIfNotNullAttribute.cs index eb0a4d48..39860bcb 100644 --- a/src/log4net/Util/NotNullIfNotNullAttribute.cs +++ b/src/log4net/Diagnostics/CodeAnalysis/NotNullIfNotNullAttribute.cs @@ -1,4 +1,4 @@ -#region Apache License +#region Apache License // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with @@ -17,10 +17,9 @@ // #endregion +#if !NET6_0_OR_GREATER namespace System.Diagnostics.CodeAnalysis; -// Not available until .NET 6, cloned from .NET code. - /// /// Specifies that the output will be non-null if the named parameter is non-null. /// @@ -43,3 +42,4 @@ public NotNullIfNotNullAttribute(string parameterName) /// public string ParameterName { get; } } +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/NotNullWhenAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/NotNullWhenAttribute.cs new file mode 100644 index 00000000..86973727 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/NotNullWhenAttribute.cs @@ -0,0 +1,43 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET6_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that when a method returns ReturnValue, +/// the parameter will not be null 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 will not be null. + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// + /// Gets the return value condition. + /// + public bool ReturnValue { get; } +} +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/NullableAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/NullableAttribute.cs new file mode 100644 index 00000000..0757cc06 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/NullableAttribute.cs @@ -0,0 +1,39 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +using System.Diagnostics.CodeAnalysis; + +namespace System.Runtime.CompilerServices; + +/// +[AttributeUsage(AttributeTargets.GenericParameter | AttributeTargets.ReturnValue | AttributeTargets.Parameter | AttributeTargets.Event | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] +internal sealed class NullableAttribute : Attribute +{ + /// + [SuppressMessage("Style", "KR1010:Class field names should be camelCased")] + [SuppressMessage("Design", "CA1051:Do not declare visible instance fields")] + public readonly byte[] NullableFlags; + + /// + [SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] + public NullableAttribute(byte nullableFlags) => NullableFlags = new[] { nullableFlags }; + + /// + public NullableAttribute(byte[] nullableFlags) => NullableFlags = nullableFlags; +} \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/NullableContextAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/NullableContextAttribute.cs new file mode 100644 index 00000000..0b16d806 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/NullableContextAttribute.cs @@ -0,0 +1,36 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +using System.Diagnostics.CodeAnalysis; + +namespace System.Runtime.CompilerServices; + +/// +[AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Module, AllowMultiple = false, Inherited = false)] +internal sealed class NullableContextAttribute : Attribute +{ + /// + [SuppressMessage("Style", "KR1010:Class field names should be camelCased")] + [SuppressMessage("Design", "CA1051:Do not declare visible instance fields")] + public readonly byte Flag; + + /// + [SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] + public NullableContextAttribute(byte flag) => Flag = flag; +} \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/RequiredMemberAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/RequiredMemberAttribute.cs new file mode 100644 index 00000000..a824e6b2 --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/RequiredMemberAttribute.cs @@ -0,0 +1,29 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET7_0_OR_GREATER +namespace System.Runtime.CompilerServices; + +/// +/// Specifies that a type has required members or that a member is required +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)] +internal sealed class RequiredMemberAttribute : Attribute +{ } +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/SetsRequiredMembersAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/SetsRequiredMembersAttribute.cs new file mode 100644 index 00000000..d844d8fe --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/SetsRequiredMembersAttribute.cs @@ -0,0 +1,30 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if !NET7_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that this constructor sets all required members for the current type, +/// and callers do not need to set any required members themselves. +/// +[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] +internal sealed class SetsRequiredMembersAttribute : Attribute +{ } +#endif \ No newline at end of file diff --git a/src/log4net/Diagnostics/CodeAnalysis/ValidatedNotNullAttribute.cs b/src/log4net/Diagnostics/CodeAnalysis/ValidatedNotNullAttribute.cs new file mode 100644 index 00000000..8884216f --- /dev/null +++ b/src/log4net/Diagnostics/CodeAnalysis/ValidatedNotNullAttribute.cs @@ -0,0 +1,29 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Attribute to tell Roslyn-Analyzers that a parameter will be checked for +/// +// https://github.com/dotnet/roslyn-analyzers/issues/2215 +// https://github.com/dotnet/roslyn-analyzers/blob/main/src/NetAnalyzers/UnitTests/Microsoft.CodeQuality.Analyzers/QualityGuidelines/ValidateArgumentsOfPublicMethodsTests.cs + +[AttributeUsage(AttributeTargets.Parameter)] +internal sealed class ValidatedNotNullAttribute : Attribute { } \ No newline at end of file