dotnet / dotnet/dotnet-api-docs
XmlBinaryWriterSession.TryAdd: incorrect description of return values
- Lingua principale
- C#
- Stelle
- 949
- Fork
- 1.7k
- Merge medio
- 2g 19h
- PR unite (30g)
- 52
Descrizione
[Link to the documentation](https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmlbinarywritersession.tryadd?view=net-7.0)
The description of return values is as follows:
> Returns
> Boolean
> **true** if the string could be added; otherwise, **false**.
But in fact the `TryAdd` method never returns `false`.
The code:
```csharp
public virtual bool TryAdd(XmlDictionaryString value, out int key)
{
ArgumentNullException.ThrowIfNull(value);
IntArray? keys;
if (_maps.TryGetValue(value.Dictionary, out keys))
{
key = (keys[value.Key] - 1);
if (key != -1)
{
// If the key is already set, then something is wrong
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlKeyAlreadyExists));
}
key = Add(value.Value);
keys[value.Key] = (key + 1);
return true;
}
key = Add(value.Value);
keys = AddKeys(value.Dictionary, value.Key + 1);
keys[value.Key] = (key + 1);
return true;
}
```
[Link to the sources](https://github.com/dotnet/runtime/blob/d099f075e45d2aa6007a22b71b45a08758559f80/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryWriterSession.cs#L28)
The `TryAdd` method returns `true` or throws an exception, but it doesn't return `false`.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Start with the linked XmlBinaryWriterSession.TryAdd API documentation and compare its Returns section with the source at src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryWriterSession.cs. Update the return-value description to match the method behavior, then verify the rendered API documentation.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 48/100