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

Improve annotations for XLinq methods taking params object[] #43717

Merged
merged 4 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ public void Add(object? content)
AddNode(new XElement(x));
return;
}
object[]? o = content as object[];
object?[]? o = content as object?[];
if (o != null)
{
foreach (object obj in o) Add(obj);
foreach (object? obj in o) Add(obj);
return;
}
IEnumerable? e = content as IEnumerable;
if (e != null)
{
foreach (object obj in e) Add(obj);
foreach (object? obj in e) Add(obj);
return;
}
AddString(GetStringValue(content));
Expand All @@ -190,7 +190,7 @@ public void Add(object? content)
/// See XContainer.Add(object content) for details about the content that can be added
/// using this method.
/// </remarks>
public void Add(params object[] content)
public void Add(params object?[] content)
{
Add((object)content);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public void AddFirst(object? content)
/// <exception cref="InvalidOperationException">
/// Thrown if the parent is null.
/// </exception>
public void AddFirst(params object[] content)
public void AddFirst(params object?[] content)
{
AddFirst((object)content);
}
Expand Down Expand Up @@ -452,7 +452,7 @@ public void ReplaceNodes(object? content)
/// See XContainer.Add(object content) for details about the content that can be added
/// using this method.
/// </remarks>
public void ReplaceNodes(params object[] content)
public void ReplaceNodes(params object?[] content)
{
ReplaceNodes((object)content);
}
Expand Down Expand Up @@ -492,16 +492,16 @@ internal void AddContentSkipNotify(object? content)
AddNodeSkipNotify(new XElement(x));
return;
}
object[]? o = content as object[];
object?[]? o = content as object?[];
if (o != null)
{
foreach (object obj in o) AddContentSkipNotify(obj);
foreach (object? obj in o) AddContentSkipNotify(obj);
return;
}
IEnumerable? e = content as IEnumerable;
if (e != null)
{
foreach (object obj in e) AddContentSkipNotify(obj);
foreach (object? obj in e) AddContentSkipNotify(obj);
return;
}
AddStringSkipNotify(GetStringValue(content));
Expand Down Expand Up @@ -1389,7 +1389,7 @@ internal async Task WriteContentToAsync(XmlWriter writer, CancellationToken canc
}
}

private static void AddContentToList(List<object> list, object content)
private static void AddContentToList(List<object?> list, object? content)
{
IEnumerable? e = content is string ? null : content as IEnumerable;
if (e == null)
Expand All @@ -1398,7 +1398,7 @@ private static void AddContentToList(List<object> list, object content)
}
else
{
foreach (object obj in e)
foreach (object? obj in e)
{
if (obj != null) AddContentToList(list, obj);
}
Expand All @@ -1409,7 +1409,7 @@ private static void AddContentToList(List<object> list, object content)
internal static object? GetContentSnapshot(object? content)
{
if (content is string || !(content is IEnumerable)) return content;
List<object> list = new List<object>();
List<object?> list = new List<object?>();
AddContentToList(list, content);
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public XDocument()
/// See <see cref="XContainer.Add(object)"/> for details about the content that can be added
/// using this method.
/// </remarks>
public XDocument(params object[] content)
public XDocument(params object?[] content)
: this()
{
AddContentSkipNotify(content);
Expand Down Expand Up @@ -87,7 +87,7 @@ public XDocument(params object[] content)
/// See <see cref="XContainer.Add(object)"/> for details about the content that can be added
/// using this method.
/// </remarks>
public XDocument(XDeclaration? declaration, params object[] content)
public XDocument(XDeclaration? declaration, params object?[] content)
: this(content)
{
_declaration = declaration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public XElement(XName name, object? content)
/// See XContainer.Add(object content) for details about the content that can be added
/// using this method.
/// </remarks>
public XElement(XName name, params object[] content) : this(name, (object)content) { }
public XElement(XName name, params object?[] content) : this(name, (object)content) { }

/// <summary>
/// Initializes a new instance of the XElement class from another XElement object.
Expand Down Expand Up @@ -983,7 +983,7 @@ public void ReplaceAll(object? content)
/// See XContainer.Add(object content) for details about the content that can be added
/// using this method.
/// </remarks>
public void ReplaceAll(params object[] content)
public void ReplaceAll(params object?[] content)
{
ReplaceAll((object)content);
}
Expand Down Expand Up @@ -1020,7 +1020,7 @@ public void ReplaceAttributes(object? content)
/// See XContainer.Add(object content) for details about the content that can be added
/// using this method.
/// </remarks>
public void ReplaceAttributes(params object[] content)
public void ReplaceAttributes(params object?[] content)
{
ReplaceAttributes((object)content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ private void AddContent(object? content)
AddNode(new XElement(x));
return;
}
object[]? o = content as object[];
object?[]? o = content as object?[];
if (o != null)
{
foreach (object obj in o) AddContent(obj);
foreach (object? obj in o) AddContent(obj);
return;
}
IEnumerable? e = content as IEnumerable;
if (e != null)
{
foreach (object obj in e) AddContent(obj);
foreach (object? obj in e) AddContent(obj);
return;
}
if (content is XAttribute) throw new ArgumentException(SR.Argument_AddAttribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void AddAfterSelf(object? content)
/// <exception cref="InvalidOperationException">
/// Thrown if the parent is null.
/// </exception>
public void AddAfterSelf(params object[] content)
public void AddAfterSelf(params object?[] content)
krwq marked this conversation as resolved.
Show resolved Hide resolved
{
AddAfterSelf((object)content);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public void AddBeforeSelf(object? content)
/// <exception cref="InvalidOperationException">
/// Thrown if the parent is null.
/// </exception>
public void AddBeforeSelf(params object[] content)
public void AddBeforeSelf(params object?[] content)
{
AddBeforeSelf((object)content);
}
Expand Down Expand Up @@ -567,7 +567,7 @@ public void ReplaceWith(object? content)
/// Replaces this node with the specified content.
/// </summary>
/// <param name="content">Content that replaces this node.</param>
public void ReplaceWith(params object[] content)
public void ReplaceWith(params object?[] content)
{
ReplaceWith((object)content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public XStreamingElement(XName name)
/// </summary>
/// <param name="name">The name to assign to the new <see cref="XStreamingElement"/> node</param>
/// <param name="content">The content to assign to the new <see cref="XStreamingElement"/> node</param>
public XStreamingElement(XName name, object content)
public XStreamingElement(XName name, object? content)
: this(name)
{
this.content = content is List<object> ? new object[] { content } : content;
this.content = content is List<object?> ? new object?[] { content } : content;
}

/// <summary>
/// Creates a <see cref="XStreamingElement"/> node with a given name and content
/// </summary>
/// <param name="name">The name to assign to the new <see cref="XStreamingElement"/> node</param>
/// <param name="content">An array containing content to assign to the new <see cref="XStreamingElement"/> node</param>
public XStreamingElement(XName name, params object[] content)
public XStreamingElement(XName name, params object?[] content)
: this(name)
{
this.content = content;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void Add(object? content)
/// Add content to an <see cref="XStreamingElement"/>
/// </summary>
/// <param name="content">array of objects containing content to add</param>
public void Add(params object[] content)
public void Add(params object?[] content)
{
Add((object)content);
}
Expand Down
28 changes: 14 additions & 14 deletions src/libraries/System.Xml.XDocument/ref/System.Xml.XDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ internal XContainer() { }
public System.Xml.Linq.XNode? FirstNode { get { throw null; } }
public System.Xml.Linq.XNode? LastNode { get { throw null; } }
public void Add(object? content) { }
public void Add(params object[] content) { }
public void Add(params object?[] content) { }
public void AddFirst(object? content) { }
public void AddFirst(params object[] content) { }
public void AddFirst(params object?[] content) { }
public System.Xml.XmlWriter CreateWriter() { throw null; }
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode> DescendantNodes() { throw null; }
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants() { throw null; }
Expand All @@ -163,7 +163,7 @@ public void AddFirst(params object[] content) { }
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode> Nodes() { throw null; }
public void RemoveNodes() { }
public void ReplaceNodes(object? content) { }
public void ReplaceNodes(params object[] content) { }
public void ReplaceNodes(params object?[] content) { }
}
public partial class XDeclaration
{
Expand All @@ -177,8 +177,8 @@ public XDeclaration(System.Xml.Linq.XDeclaration other) { }
public partial class XDocument : System.Xml.Linq.XContainer
{
public XDocument() { }
public XDocument(params object[] content) { }
public XDocument(System.Xml.Linq.XDeclaration? declaration, params object[] content) { }
public XDocument(params object?[] content) { }
public XDocument(System.Xml.Linq.XDeclaration? declaration, params object?[] content) { }
public XDocument(System.Xml.Linq.XDocument other) { }
public System.Xml.Linq.XDeclaration? Declaration { get { throw null; } set { } }
public System.Xml.Linq.XDocumentType? DocumentType { get { throw null; } }
Expand Down Expand Up @@ -229,7 +229,7 @@ public partial class XElement : System.Xml.Linq.XContainer, System.Xml.Serializa
public XElement(System.Xml.Linq.XElement other) { }
public XElement(System.Xml.Linq.XName name) { }
public XElement(System.Xml.Linq.XName name, object? content) { }
public XElement(System.Xml.Linq.XName name, params object[] content) { }
public XElement(System.Xml.Linq.XName name, params object?[] content) { }
public XElement(System.Xml.Linq.XStreamingElement other) { }
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> EmptySequence { get { throw null; } }
public System.Xml.Linq.XAttribute? FirstAttribute { get { throw null; } }
Expand Down Expand Up @@ -330,9 +330,9 @@ public XElement(System.Xml.Linq.XStreamingElement other) { }
public void RemoveAll() { }
public void RemoveAttributes() { }
public void ReplaceAll(object? content) { }
public void ReplaceAll(params object[] content) { }
public void ReplaceAll(params object?[] content) { }
public void ReplaceAttributes(object? content) { }
public void ReplaceAttributes(params object[] content) { }
public void ReplaceAttributes(params object?[] content) { }
public void Save(System.IO.Stream stream) { }
public void Save(System.IO.Stream stream, System.Xml.Linq.SaveOptions options) { }
public void Save(System.IO.TextWriter textWriter) { }
Expand Down Expand Up @@ -398,9 +398,9 @@ internal XNode() { }
public System.Xml.Linq.XNode? NextNode { get { throw null; } }
public System.Xml.Linq.XNode? PreviousNode { get { throw null; } }
public void AddAfterSelf(object? content) { }
public void AddAfterSelf(params object[] content) { }
public void AddAfterSelf(params object?[] content) { }
public void AddBeforeSelf(object? content) { }
public void AddBeforeSelf(params object[] content) { }
public void AddBeforeSelf(params object?[] content) { }
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Ancestors() { throw null; }
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Ancestors(System.Xml.Linq.XName? name) { throw null; }
public static int CompareDocumentOrder(System.Xml.Linq.XNode? n1, System.Xml.Linq.XNode? n2) { throw null; }
Expand All @@ -419,7 +419,7 @@ public void AddBeforeSelf(params object[] content) { }
public static System.Threading.Tasks.Task<System.Xml.Linq.XNode> ReadFromAsync(System.Xml.XmlReader reader, System.Threading.CancellationToken cancellationToken) { throw null; }
public void Remove() { }
public void ReplaceWith(object? content) { }
public void ReplaceWith(params object[] content) { }
public void ReplaceWith(params object?[] content) { }
public override string ToString() { throw null; }
public string ToString(System.Xml.Linq.SaveOptions options) { throw null; }
public abstract void WriteTo(System.Xml.XmlWriter writer);
Expand Down Expand Up @@ -488,11 +488,11 @@ public override void WriteTo(System.Xml.XmlWriter writer) { }
public partial class XStreamingElement
{
public XStreamingElement(System.Xml.Linq.XName name) { }
public XStreamingElement(System.Xml.Linq.XName name, object content) { }
public XStreamingElement(System.Xml.Linq.XName name, params object[] content) { }
public XStreamingElement(System.Xml.Linq.XName name, object? content) { }
public XStreamingElement(System.Xml.Linq.XName name, params object?[] content) { }
public System.Xml.Linq.XName Name { get { throw null; } set { } }
public void Add(object? content) { }
public void Add(params object[] content) { }
public void Add(params object?[] content) { }
public void Save(System.IO.Stream stream) { }
public void Save(System.IO.Stream stream, System.Xml.Linq.SaveOptions options) { }
public void Save(System.IO.TextWriter textWriter) { }
Expand Down