Skip to content

Commit

Permalink
Enable nullability for BenchmarkDotNet.Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
alinasmirnova authored and AndreyAkinshin committed Aug 27, 2023
1 parent d391085 commit 2d763cf
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 65 deletions.
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
Loading

0 comments on commit 2d763cf

Please sign in to comment.