Dotnet-api-docs: `String.Format` and params array

Created on 30 Sep 2020  路  8Comments  路  Source: dotnet/dotnet-api-docs

The String.Format methods take a params array as an argument which looks like it's been enabled for nullable reference types.

https://github.com/dotnet/runtime/blob/118eee973af81119fd00fe75bc9c14ce3192ff1e/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs#L481-L491

However, in the docs the signature is shown as

public static string Format (string format, params object[]? args);

Is this a docs bug or should the implementation be params object[]? args?

Isn't one ( params object[]? args) effectively "a parameters array of object, where the entire argument could be null) while the other ( params object?[] args) effectively "a parameters array of nullable object, where the argument itself isn't expected to be null"?

Pri3 area-Infrastructure doc-bug

All 8 comments

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Is this a docs bug

Yup. The source has the correct signature, as does the reference assembly and resulting IntelliSense in Visual Studio:
image

As you say, object[]? is a nullable array of non-nullable objects whereas object?[] is a non-nullable array of nullable objects (and for completeness, object?[]? is a nullable array of nullable objects). string.Format takes a non-nullable array of nullable objects, object?[].

@carlossanlop, @terrajobst, what's the right way to handle this? I'm assuming this is actually a bug in whatever tooling is used to generate the signature portion of the docs?

image

I can edit the docs page and submit a PR, but that doesn't sound like the right approach here and my change would get overwritten by the tooling whenever it's generated again.

object?[]? is a nullable array of nullable objects)

That makes my head hurt! LOL

_I can edit the docs page and submit a PR, but that doesn't sound like the right approach here and my change would get overwritten by the tooling whenever it's generated again._

Thanks for offering, @scottdorman, but we need the xml to get updated via our tooling.

@joelmartinez @TianqiZhang @mimisasouvanh can you please take a look? The mdoc process placed the ? in the wrong position.

This is how it's defined in the ref file:
System.String Format(System.String format, params object?[] args)

https://github.com/dotnet/runtime/blob/1bc493ab8b65d167180ad1f41f3a6292d28d7094/src/libraries/System.Runtime/ref/System.Runtime.cs#L3516

I'll transfer this issue to the dotnet-api-docs repo.

Ping @joelmartinez @TianqiZhang

Thanks @carlossanlop ... I've created a devops item here to track this fix in mdoc.

Was this page helpful?
0 / 5 - 0 ratings