From 2d763cf1dfabd90bb47d169981aca2f0269f6a02 Mon Sep 17 00:00:00 2001 From: Alina Smirnova Date: Sun, 27 Aug 2023 14:26:56 +0200 Subject: [PATCH] Enable nullability for BenchmarkDotNet.Annotations --- .../Attributes/ArgumentsAttribute.cs | 6 +- .../Attributes/BenchmarkAttribute.cs | 2 +- .../Attributes/BenchmarkCategoryAttribute.cs | 2 +- .../Attributes/ParamsAttribute.cs | 6 +- .../BenchmarkDotNet.Annotations.csproj | 1 + .../Helpers/CodeAnnotations.cs | 115 +++++++++--------- 6 files changed, 67 insertions(+), 65 deletions(-) diff --git a/src/BenchmarkDotNet.Annotations/Attributes/ArgumentsAttribute.cs b/src/BenchmarkDotNet.Annotations/Attributes/ArgumentsAttribute.cs index 6caa31a91a..c9b8e7961c 100644 --- a/src/BenchmarkDotNet.Annotations/Attributes/ArgumentsAttribute.cs +++ b/src/BenchmarkDotNet.Annotations/Attributes/ArgumentsAttribute.cs @@ -6,13 +6,13 @@ namespace BenchmarkDotNet.Attributes [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class ArgumentsAttribute : PriorityAttribute { - public object[] Values { get; } + public object?[] Values { get; } // CLS-Compliant Code requires a constructor without an array in the argument list [PublicAPI] public ArgumentsAttribute() => Values = new object[0]; - public ArgumentsAttribute(params object[] values) - => Values = values ?? new object[] { null }; // when users do Arguments(null) they mean one, null argument + public ArgumentsAttribute(params object?[]? values) + => Values = values ?? new object?[] { null }; // when users do Arguments(null) they mean one, null argument } } \ No newline at end of file diff --git a/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkAttribute.cs b/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkAttribute.cs index 377e737b96..55354dd52b 100644 --- a/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkAttribute.cs +++ b/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkAttribute.cs @@ -14,7 +14,7 @@ public BenchmarkAttribute([CallerLineNumber] int sourceCodeLineNumber = 0, [Call SourceCodeFile = sourceCodeFile; } - public string Description { get; set; } + public string? Description { get; set; } public bool Baseline { get; set; } diff --git a/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkCategoryAttribute.cs b/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkCategoryAttribute.cs index f386d6cae4..332fe7d176 100644 --- a/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkCategoryAttribute.cs +++ b/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkCategoryAttribute.cs @@ -9,7 +9,7 @@ public class BenchmarkCategoryAttribute : Attribute public string[] Categories { get; } // CLS-Compliant Code requires a constructor without an array in the argument list - [PublicAPI] protected BenchmarkCategoryAttribute() { } + [PublicAPI] protected BenchmarkCategoryAttribute() => Categories = new string[0]; public BenchmarkCategoryAttribute(params string[] categories) => Categories = categories; } diff --git a/src/BenchmarkDotNet.Annotations/Attributes/ParamsAttribute.cs b/src/BenchmarkDotNet.Annotations/Attributes/ParamsAttribute.cs index 6911657d5e..22148ffa64 100644 --- a/src/BenchmarkDotNet.Annotations/Attributes/ParamsAttribute.cs +++ b/src/BenchmarkDotNet.Annotations/Attributes/ParamsAttribute.cs @@ -5,12 +5,12 @@ namespace BenchmarkDotNet.Attributes [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public class ParamsAttribute : PriorityAttribute { - public object[] Values { get; } + public object?[] Values { get; } // CLS-Compliant Code requires a constructor without an array in the argument list public ParamsAttribute() => Values = new object[0]; - public ParamsAttribute(params object[] values) - => Values = values ?? new object[] { null }; // when users do Params(null) they mean one, null argument + public ParamsAttribute(params object?[]? values) + => Values = values ?? new object?[] { null }; // when users do Params(null) they mean one, null argument } } diff --git a/src/BenchmarkDotNet.Annotations/BenchmarkDotNet.Annotations.csproj b/src/BenchmarkDotNet.Annotations/BenchmarkDotNet.Annotations.csproj index 4848f1009b..2e7361e163 100644 --- a/src/BenchmarkDotNet.Annotations/BenchmarkDotNet.Annotations.csproj +++ b/src/BenchmarkDotNet.Annotations/BenchmarkDotNet.Annotations.csproj @@ -9,6 +9,7 @@ BenchmarkDotNet True + enable diff --git a/src/BenchmarkDotNet/Helpers/CodeAnnotations.cs b/src/BenchmarkDotNet/Helpers/CodeAnnotations.cs index 898e44cb32..b8ddc0fabb 100644 --- a/src/BenchmarkDotNet/Helpers/CodeAnnotations.cs +++ b/src/BenchmarkDotNet/Helpers/CodeAnnotations.cs @@ -20,6 +20,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#nullable enable using System; // ReSharper disable All @@ -126,12 +127,12 @@ internal sealed class StringFormatMethodAttribute : Attribute /// /// Specifies which parameter of an annotated method should be treated as the format string /// - public StringFormatMethodAttribute([NotNull] string formatParameterName) + public StringFormatMethodAttribute(string formatParameterName) { FormatParameterName = formatParameterName; } - [NotNull] public string FormatParameterName { get; } + public string FormatParameterName { get; } } /// @@ -166,12 +167,12 @@ public StringFormatMethodAttribute([NotNull] string formatParameterName) AllowMultiple = true)] internal sealed class ValueProviderAttribute : Attribute { - public ValueProviderAttribute([NotNull] string name) + public ValueProviderAttribute(string name) { Name = name; } - [NotNull] public string Name { get; } + public string Name { get; } } /// @@ -231,12 +232,12 @@ internal sealed class NotifyPropertyChangedInvocatorAttribute : Attribute { public NotifyPropertyChangedInvocatorAttribute() { } - public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) + public NotifyPropertyChangedInvocatorAttribute(string parameterName) { ParameterName = parameterName; } - [CanBeNull] public string ParameterName { get; } + public string? ParameterName { get; } } /// @@ -286,16 +287,16 @@ public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] internal sealed class ContractAnnotationAttribute : Attribute { - public ContractAnnotationAttribute([NotNull] string contract) + public ContractAnnotationAttribute(string contract) : this(contract, false) { } - public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates) + public ContractAnnotationAttribute(string contract, bool forceFullStates) { Contract = contract; ForceFullStates = forceFullStates; } - [NotNull] public string Contract { get; } + public string Contract { get; } public bool ForceFullStates { get; } } @@ -360,12 +361,12 @@ internal sealed class CannotApplyEqualityOperatorAttribute : Attribute { } [BaseTypeRequired(typeof(Attribute))] internal sealed class BaseTypeRequiredAttribute : Attribute { - public BaseTypeRequiredAttribute([NotNull] Type baseType) + public BaseTypeRequiredAttribute(Type baseType) { BaseType = baseType; } - [NotNull] public Type BaseType { get; } + public Type BaseType { get; } } /// @@ -476,12 +477,12 @@ internal sealed class PublicAPIAttribute : Attribute { public PublicAPIAttribute() { } - public PublicAPIAttribute([NotNull] string comment) + public PublicAPIAttribute(string comment) { Comment = comment; } - [CanBeNull] public string Comment { get; } + public string? Comment { get; } } /// @@ -522,12 +523,12 @@ internal sealed class MustUseReturnValueAttribute : Attribute { public MustUseReturnValueAttribute() { } - public MustUseReturnValueAttribute([NotNull] string justification) + public MustUseReturnValueAttribute(string justification) { Justification = justification; } - [CanBeNull] public string Justification { get; } + public string? Justification { get; } } /// @@ -559,12 +560,12 @@ internal sealed class PathReferenceAttribute : Attribute { public PathReferenceAttribute() { } - public PathReferenceAttribute([NotNull, PathReference] string basePath) + public PathReferenceAttribute([PathReference] string basePath) { BasePath = basePath; } - [CanBeNull] public string BasePath { get; } + public string? BasePath { get; } } /// @@ -628,7 +629,7 @@ internal sealed class MacroAttribute : Attribute /// Allows specifying a macro that will be executed for a source template /// parameter when the template is expanded. /// - [CanBeNull] public string Expression { get; set; } + public string? Expression { get; set; } /// /// Allows specifying which occurrence of the target parameter becomes editable when the template is deployed. @@ -644,73 +645,73 @@ internal sealed class MacroAttribute : Attribute /// Identifies the target parameter of a source template if the /// is applied on a template method. /// - [CanBeNull] public string Target { get; set; } + public string? Target { get; set; } } [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] internal sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute { - public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format) + public AspMvcAreaMasterLocationFormatAttribute(string format) { Format = format; } - [NotNull] public string Format { get; } + public string Format { get; } } [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] internal sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute { - public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format) + public AspMvcAreaPartialViewLocationFormatAttribute(string format) { Format = format; } - [NotNull] public string Format { get; } + public string Format { get; } } [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] internal sealed class AspMvcAreaViewLocationFormatAttribute : Attribute { - public AspMvcAreaViewLocationFormatAttribute([NotNull] string format) + public AspMvcAreaViewLocationFormatAttribute(string format) { Format = format; } - [NotNull] public string Format { get; } + public string Format { get; } } [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] internal sealed class AspMvcMasterLocationFormatAttribute : Attribute { - public AspMvcMasterLocationFormatAttribute([NotNull] string format) + public AspMvcMasterLocationFormatAttribute(string format) { Format = format; } - [NotNull] public string Format { get; } + public string Format { get; } } [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] internal sealed class AspMvcPartialViewLocationFormatAttribute : Attribute { - public AspMvcPartialViewLocationFormatAttribute([NotNull] string format) + public AspMvcPartialViewLocationFormatAttribute(string format) { Format = format; } - [NotNull] public string Format { get; } + public string Format { get; } } [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] internal sealed class AspMvcViewLocationFormatAttribute : Attribute { - public AspMvcViewLocationFormatAttribute([NotNull] string format) + public AspMvcViewLocationFormatAttribute(string format) { Format = format; } - [NotNull] public string Format { get; } + public string Format { get; } } /// @@ -724,12 +725,12 @@ internal sealed class AspMvcActionAttribute : Attribute { public AspMvcActionAttribute() { } - public AspMvcActionAttribute([NotNull] string anonymousProperty) + public AspMvcActionAttribute(string anonymousProperty) { AnonymousProperty = anonymousProperty; } - [CanBeNull] public string AnonymousProperty { get; } + public string? AnonymousProperty { get; } } /// @@ -742,12 +743,12 @@ internal sealed class AspMvcAreaAttribute : Attribute { public AspMvcAreaAttribute() { } - public AspMvcAreaAttribute([NotNull] string anonymousProperty) + public AspMvcAreaAttribute(string anonymousProperty) { AnonymousProperty = anonymousProperty; } - [CanBeNull] public string AnonymousProperty { get; } + public string? AnonymousProperty { get; } } /// @@ -761,12 +762,12 @@ internal sealed class AspMvcControllerAttribute : Attribute { public AspMvcControllerAttribute() { } - public AspMvcControllerAttribute([NotNull] string anonymousProperty) + public AspMvcControllerAttribute(string anonymousProperty) { AnonymousProperty = anonymousProperty; } - [CanBeNull] public string AnonymousProperty { get; } + public string? AnonymousProperty { get; } } /// @@ -864,23 +865,23 @@ internal sealed class HtmlElementAttributesAttribute : Attribute { public HtmlElementAttributesAttribute() { } - public HtmlElementAttributesAttribute([NotNull] string name) + public HtmlElementAttributesAttribute(string name) { Name = name; } - [CanBeNull] public string Name { get; } + public string? Name { get; } } [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] internal sealed class HtmlAttributeValueAttribute : Attribute { - public HtmlAttributeValueAttribute([NotNull] string name) + public HtmlAttributeValueAttribute(string name) { Name = name; } - [NotNull] public string Name { get; } + public string Name { get; } } /// @@ -1065,15 +1066,15 @@ internal sealed class XamlItemBindingOfItemsControlAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] internal sealed class AspChildControlTypeAttribute : Attribute { - public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType) + public AspChildControlTypeAttribute(string tagName, Type controlType) { TagName = tagName; ControlType = controlType; } - [NotNull] public string TagName { get; } + public string TagName { get; } - [NotNull] public Type ControlType { get; } + public Type ControlType { get; } } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] @@ -1088,12 +1089,12 @@ internal sealed class AspMethodPropertyAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] internal sealed class AspRequiredAttributeAttribute : Attribute { - public AspRequiredAttributeAttribute([NotNull] string attribute) + public AspRequiredAttributeAttribute(string attribute) { Attribute = attribute; } - [NotNull] public string Attribute { get; } + public string Attribute { get; } } [AttributeUsage(AttributeTargets.Property)] @@ -1110,55 +1111,55 @@ public AspTypePropertyAttribute(bool createConstructorReferences) [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class RazorImportNamespaceAttribute : Attribute { - public RazorImportNamespaceAttribute([NotNull] string name) + public RazorImportNamespaceAttribute(string name) { Name = name; } - [NotNull] public string Name { get; } + public string Name { get; } } [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class RazorInjectionAttribute : Attribute { - public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName) + public RazorInjectionAttribute(string type, string fieldName) { Type = type; FieldName = fieldName; } - [NotNull] public string Type { get; } + public string Type { get; } - [NotNull] public string FieldName { get; } + public string FieldName { get; } } [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class RazorDirectiveAttribute : Attribute { - public RazorDirectiveAttribute([NotNull] string directive) + public RazorDirectiveAttribute(string directive) { Directive = directive; } - [NotNull] public string Directive { get; } + public string Directive { get; } } [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class RazorPageBaseTypeAttribute : Attribute { - public RazorPageBaseTypeAttribute([NotNull] string baseType) + public RazorPageBaseTypeAttribute(string baseType) { BaseType = baseType; } - public RazorPageBaseTypeAttribute([NotNull] string baseType, string pageName) + public RazorPageBaseTypeAttribute(string baseType, string pageName) { BaseType = baseType; PageName = pageName; } - [NotNull] public string BaseType { get; } - [CanBeNull] public string PageName { get; } + public string BaseType { get; } + public string? PageName { get; } } [AttributeUsage(AttributeTargets.Method)]