Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullability for BenchmarkDotNet.Annotations #2418

Merged
merged 2 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/BenchmarkDotNet.Annotations/Attributes/ParamsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<RootNamespace>BenchmarkDotNet</RootNamespace>
<!-- needed for docfx xref resolver -->
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\BenchmarkDotNet\Helpers\CodeAnnotations.cs" Link="Attributes\CodeAnnotations.cs" />
Expand Down