UnmanagedBuffer = 2,
}
}
-#nullable disable
namespace System.Xml
{
[System.ObsoleteAttribute("XmlDataDocument class will be removed in a future release.")]
public XmlDataDocument(System.Data.DataSet dataset) { }
public System.Data.DataSet DataSet { get { throw null; } }
public override System.Xml.XmlNode CloneNode(bool deep) { throw null; }
- public override System.Xml.XmlElement CreateElement(string prefix, string localName, string namespaceURI) { throw null; }
+ public override System.Xml.XmlElement CreateElement(string? prefix, string localName, string? namespaceURI) { throw null; }
public override System.Xml.XmlEntityReference CreateEntityReference(string name) { throw null; }
- protected override System.Xml.XPath.XPathNavigator CreateNavigator(System.Xml.XmlNode node) { throw null; }
- public override System.Xml.XmlElement GetElementById(string elemId) { throw null; }
+ protected override System.Xml.XPath.XPathNavigator? CreateNavigator(System.Xml.XmlNode node) { throw null; }
+ public override System.Xml.XmlElement? GetElementById(string elemId) { throw null; }
public System.Xml.XmlElement GetElementFromRow(System.Data.DataRow r) { throw null; }
public override System.Xml.XmlNodeList GetElementsByTagName(string name) { throw null; }
- public System.Data.DataRow GetRowFromElement(System.Xml.XmlElement e) { throw null; }
+ public System.Data.DataRow? GetRowFromElement(System.Xml.XmlElement? e) { throw null; }
public override void Load(System.IO.Stream inStream) { }
public override void Load(System.IO.TextReader txtReader) { }
public override void Load(string filename) { }
public override void Load(System.Xml.XmlReader reader) { }
}
}
-#nullable enable
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
namespace System.Xml
{
this.mapper = mapper;
}
- internal abstract XmlNode CurrentNode { get; }
+ internal abstract XmlNode? CurrentNode { get; }
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal abstract bool Next();
+
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal abstract bool NextRight();
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal bool NextRowElement()
{
while (Next())
return false;
}
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal bool NextRightRowElement()
{
if (NextRight())
}
// Returns true if the current node is on a row element (head of a region)
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal bool OnRowElement()
{
- XmlBoundElement be = CurrentNode as XmlBoundElement;
- return (be != null) && (be.Row != null);
+ return CurrentNode is XmlBoundElement be && be.Row != null;
}
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Xml.XPath;
#pragma warning disable 0618 // ignore obsolete warning about XmlDataDocument
get
{
XPathNodeType xnt = _curNode.NodeType;
- return xnt == XPathNodeType.Element || xnt == XPathNodeType.Root ? _curNode.InnerText : _curNode.Value;
+ return xnt == XPathNodeType.Element || xnt == XPathNodeType.Root ? _curNode.InnerText : _curNode.Value!;
}
}
}
_temp.MoveTo(_curNode);
- return _temp.MoveToAttribute(localName, namespaceURI) ? _temp.Value : string.Empty;
+ return _temp.MoveToAttribute(localName, namespaceURI) ? _temp.Value! : string.Empty;
}
public override string GetNamespace(string name) => _curNode.GetNamespace(name);
{
if (other != null)
{
- DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
+ DataDocumentXPathNavigator? otherDataDocXPathNav = other as DataDocumentXPathNavigator;
if (otherDataDocXPathNav != null && _curNode.MoveTo(otherDataDocXPathNav.CurNode))
{
_doc = _curNode.Document;
{
if (other != null)
{
- DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
+ DataDocumentXPathNavigator? otherDataDocXPathNav = other as DataDocumentXPathNavigator;
if (otherDataDocXPathNav != null &&
_doc == otherDataDocXPathNav.Document && _curNode.IsSamePosition(otherDataDocXPathNav.CurNode))
{
//the function is only called for XPathNodeList enumerate nodes and
// shouldn't be promoted to frequently use because it will cause foliation
- XmlNode IHasXmlNode.GetNode() => _curNode.Node;
+ XmlNode IHasXmlNode.GetNode() => _curNode.Node!;
- public override XmlNodeOrder ComparePosition(XPathNavigator other)
+ public override XmlNodeOrder ComparePosition(XPathNavigator? other)
{
if (other == null)
{
return XmlNodeOrder.Unknown; // this is what XPathDocument does.
}
- DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
+ DataDocumentXPathNavigator? otherDataDocXPathNav = other as DataDocumentXPathNavigator;
return otherDataDocXPathNav == null || otherDataDocXPathNav.Document != _doc ?
XmlNodeOrder.Unknown :
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Data;
using System.Diagnostics;
{
private XmlDataDocument _doc;
private XmlNode _node;
- private DataColumn _column;
+ private DataColumn? _column;
private bool _fOnValue;
private bool _bNeedFoliate;
private bool _isInUse;
internal void AddPointer() => _doc.AddPointer(this);
// Returns the row element of the region that the pointer points into
- private XmlBoundElement GetRowElement()
+ private XmlBoundElement? GetRowElement()
{
- XmlBoundElement rowElem;
+ XmlBoundElement? rowElem;
if (_column != null)
{
rowElem = _node as XmlBoundElement;
return rowElem;
}
- private DataRow Row
+ private DataRow? Row
{
get
{
- XmlBoundElement rowElem = GetRowElement();
+ XmlBoundElement? rowElem = GetRowElement();
if (rowElem == null)
{
return null;
AssertValid();
}
- private void MoveTo(XmlNode node, DataColumn column, bool fOnValue)
+ private void MoveTo(XmlNode node, DataColumn? column, bool fOnValue)
{
// You should not move outside of this document
Debug.Assert(node == _doc || node.OwnerDocument == _doc);
AssertValid();
}
- private DataColumn NextColumn(DataRow row, DataColumn col, bool fAttribute, bool fNulls)
+ private DataColumn? NextColumn(DataRow row, DataColumn? col, bool fAttribute, bool fNulls)
{
if (row.RowState == DataRowState.Deleted)
{
return null;
}
- private DataColumn NthColumn(DataRow row, bool fAttribute, int iColumn, bool fNulls)
+ private DataColumn? NthColumn(DataRow row, bool fAttribute, int iColumn, bool fNulls)
{
- DataColumn c = null;
+ DataColumn? c = null;
while ((c = NextColumn(row, c, fAttribute, fNulls)) != null)
{
if (iColumn == 0)
private int ColumnCount(DataRow row, bool fAttribute, bool fNulls)
{
- DataColumn c = null;
+ DataColumn? c = null;
int count = 0;
while ((c = NextColumn(row, c, fAttribute, fNulls)) != null)
{
else if (!IsFoliated(_node))
{
// find virtual column elements first
- DataColumn c = NextColumn(Row, null, false, false);
+ DataColumn? c = NextColumn(Row!, null, false, false);
if (c != null)
{
MoveTo(_node, c, _doc.IsTextOnly(c));
}
// look for anything
- XmlNode n = _doc.SafeFirstChild(_node);
+ XmlNode? n = _doc.SafeFirstChild(_node);
if (n != null)
{
MoveTo(n);
return false;
}
- DataColumn c = NextColumn(Row, _column, false, false);
+ DataColumn? c = NextColumn(Row!, _column, false, false);
if (c != null)
{
MoveTo(_node, c, false);
return true;
}
- XmlNode n = _doc.SafeFirstChild(_node);
+ XmlNode? n = _doc.SafeFirstChild(_node);
if (n != null)
{
MoveTo(n);
}
else
{
- XmlNode n = _doc.SafeNextSibling(_node);
+ XmlNode? n = _doc.SafeNextSibling(_node);
if (n != null)
{
MoveTo(n);
}
else
{
- XmlNode n = _node.ParentNode;
+ XmlNode? n = _node.ParentNode;
if (n != null)
{
MoveTo(n);
}
else if (_node.NodeType == XmlNodeType.Attribute)
{
- XmlNode n = ((XmlAttribute)_node).OwnerElement;
+ XmlNode? n = ((XmlAttribute)_node).OwnerElement;
if (n != null)
{
MoveTo(n, null, false);
{
if (!IsFoliated(_node))
{
- return ColumnCount(Row, true, false);
+ return ColumnCount(Row!, true, false);
}
else
{
- return _node.Attributes.Count;
+ return _node.Attributes!.Count;
}
}
}
{
if (!IsFoliated(_node))
{
- DataColumn c = NthColumn(Row, true, i, false);
+ DataColumn? c = NthColumn(Row!, true, i, false);
if (c != null)
{
MoveTo(_node, c, false);
}
else
{
- XmlNode n = _node.Attributes.Item(i);
+ XmlNode? n = _node.Attributes!.Item(i);
if (n != null)
{
MoveTo(n, null, false);
}
}
- internal string Value
+ internal string? Value
{
get
{
}
else if (_column.ColumnMapping == MappingType.Attribute || _fOnValue)
{
- DataRow row = Row;
+ DataRow row = Row!;
DataRowVersion rowVersion = (row.RowState == DataRowState.Detached) ? DataRowVersion.Proposed : DataRowVersion.Current;
object value = row[_column, rowVersion];
if (!Convert.IsDBNull(value))
return nodeToCheck == _node;
}
- bool IXmlDataVirtualNode.IsOnColumn(DataColumn col)
+ bool IXmlDataVirtualNode.IsOnColumn(DataColumn? col)
{
RealFoliate();
return col == _column;
return;
}
- XmlNode n = null;
+ XmlNode? n = null;
- if (_doc.IsTextOnly(_column))
+ if (_doc.IsTextOnly(_column!))
{
n = _node.FirstChild;
}
else
{
- if (_column.ColumnMapping == MappingType.Attribute)
+ if (_column!.ColumnMapping == MappingType.Attribute)
{
- n = _node.Attributes.GetNamedItem(_column.EncodedColumnName, _column.Namespace);
+ n = _node.Attributes!.GetNamedItem(_column.EncodedColumnName, _column.Namespace);
}
else
{
}
//for the 6 properties below, only when the this.column == null that the nodetype could be XmlDeclaration node
- internal string PublicId
+ internal string? PublicId
{
get
{
}
}
- internal string SystemId
+ internal string? SystemId
{
get
{
}
}
- internal string InternalSubset
+ internal string? InternalSubset
{
get
{
}
}
- internal XmlDeclaration Declaration
+ internal XmlDeclaration? Declaration
{
get
{
- XmlNode child = _doc.SafeFirstChild(_doc);
+ XmlNode? child = _doc.SafeFirstChild(_doc);
if (child != null && child.NodeType == XmlNodeType.XmlDeclaration)
return (XmlDeclaration)child;
return null;
}
}
- internal string Encoding
+ internal string? Encoding
{
get
{
}
else if (NodeType == XmlNodeType.Document)
{
- XmlDeclaration dec = Declaration;
+ XmlDeclaration? dec = Declaration;
if (dec != null)
{
return dec.Encoding;
}
}
- internal string Standalone
+ internal string? Standalone
{
get
{
}
else if (NodeType == XmlNodeType.Document)
{
- XmlDeclaration dec = Declaration;
+ XmlDeclaration? dec = Declaration;
if (dec != null)
{
return dec.Standalone;
}
}
- internal string Version
+ internal string? Version
{
get
{
}
else if (NodeType == XmlNodeType.Document)
{
- XmlDeclaration dec = Declaration;
+ XmlDeclaration? dec = Declaration;
if (dec != null)
return dec.Version;
}
if (_column != null)
{
// We must be on a de-foliated region
- XmlBoundElement rowElem = _node as XmlBoundElement;
+ XmlBoundElement? rowElem = _node as XmlBoundElement;
Debug.Assert(rowElem != null);
- DataRow row = rowElem.Row;
+ DataRow? row = rowElem.Row;
Debug.Assert(row != null);
ElementState state = rowElem.ElementState;
internal void SetNoLongerUse()
{
- _node = null;
+ _node = null!;
_column = null;
_fOnValue = false;
_bNeedFoliate = false;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Collections;
using System.Data;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
#pragma warning disable 0618 // ignore obsolete warning about XmlDataDocument
private Hashtable _tableSchemaMap; // maps an string (currently this is localName:nsURI) to a DataTable. Used to quickly find if a bound-elem matches any data-table metadata..
private Hashtable _columnSchemaMap; // maps a string (table localName:nsURI) to a Hashtable. The 2nd hastable (the one that is stored as data in columnSchemaMap, maps a string to a DataColumn.
- private XmlDataDocument _doc; // The document this mapper is related to
- private DataSet _dataSet; // The dataset this mapper is related to
+ private XmlDataDocument? _doc; // The document this mapper is related to
+ private DataSet? _dataSet; // The dataset this mapper is related to
internal const string strReservedXmlns = "http://www.w3.org/2000/xmlns/";
internal DataSetMapper()
internal DataTable SearchMatchingTableSchema(string localName, string namespaceURI)
{
object tid = GetIdentity(localName, namespaceURI);
- return (DataTable)(_tableSchemaMap[tid]);
+ return (DataTable)(_tableSchemaMap[tid]!);
}
// SearchMatchingTableSchema function works only when the elem has not been bound to a DataRow. If you want to get the table associated w/ an element after
// a column from the parent region table, then the node is NOT associated w/ a DataTable (it is a potential DataColumn in the parent region)
// 3.3.2 Else the node is a row-element (and associated w/ a DataTable / DataRow )
//
- internal DataTable SearchMatchingTableSchema(XmlBoundElement rowElem, XmlBoundElement elem)
+ internal DataTable? SearchMatchingTableSchema(XmlBoundElement? rowElem, XmlBoundElement elem)
{
Debug.Assert(elem != null);
// Currently we expect we map things from top of the tree to the bottom
Debug.Assert(rowElem.Row != null);
- DataColumn col = GetColumnSchemaForNode(rowElem, elem);
+ DataColumn? col = GetColumnSchemaForNode(rowElem, elem);
if (col == null)
{
return t;
}
}
- for (XmlNode n = elem.FirstChild; n != null; n = n.NextSibling)
+ for (XmlNode? n = elem.FirstChild; n != null; n = n.NextSibling)
{
if (n.NodeType == XmlNodeType.Element)
{
return null;
}
- internal DataColumn GetColumnSchemaForNode(XmlBoundElement rowElem, XmlNode node)
+ internal DataColumn? GetColumnSchemaForNode(XmlBoundElement rowElem, XmlNode node)
{
Debug.Assert(rowElem != null);
// The caller must make sure that node is not a row-element
object tid = GetIdentity(rowElem.LocalName, rowElem.NamespaceURI);
object cid = GetIdentity(node.LocalName, node.NamespaceURI);
- Hashtable columns = (Hashtable)_columnSchemaMap[tid];
+ Hashtable? columns = (Hashtable?)_columnSchemaMap[tid];
if (columns != null)
{
- DataColumn col = (DataColumn)(columns[cid]);
+ DataColumn? col = (DataColumn?)(columns[cid]);
if (col == null)
{
return null;
}
return null;
}
- internal DataTable GetTableSchemaForElement(XmlElement elem)
+ internal DataTable? GetTableSchemaForElement(XmlElement elem)
{
- XmlBoundElement be = elem as XmlBoundElement;
+ XmlBoundElement? be = elem as XmlBoundElement;
if (be == null)
{
return null;
return GetTableSchemaForElement(be);
}
- internal DataTable GetTableSchemaForElement(XmlBoundElement be) => be.Row?.Table;
+ internal DataTable? GetTableSchemaForElement(XmlBoundElement be) => be.Row?.Table;
internal static bool IsNotMapped(DataColumn c) => c.ColumnMapping == MappingType.Hidden;
// XmlElement e = be;
// GetRowFromElement( be ); // Calls GetRowFromElement( XmlBoundElement )
// GetRowFromElement( e ); // Calls GetRowFromElement( XmlElement ), in spite of e beeing an instance of XmlBoundElement
- internal DataRow GetRowFromElement(XmlElement e) => (e as XmlBoundElement)?.Row;
+ internal DataRow? GetRowFromElement(XmlElement? e) => (e as XmlBoundElement)?.Row;
- internal DataRow GetRowFromElement(XmlBoundElement be) => be.Row;
+ internal DataRow? GetRowFromElement(XmlBoundElement be) => be.Row;
// Get the row-elem associatd w/ the region node is in.
// If node is in a region not mapped (like document element node) the function returns false and sets elem to null)
// This function does not work if the region is not associated w/ a DataRow (it uses DataRow association to know what is the row element associated w/ the region)
- internal bool GetRegion(XmlNode node, out XmlBoundElement rowElem)
+ internal bool GetRegion(XmlNode? node, [NotNullWhen(true)] out XmlBoundElement? rowElem)
{
while (node != null)
{
- XmlBoundElement be = node as XmlBoundElement;
+ XmlBoundElement? be = node as XmlBoundElement;
// Break if found a region
if (be != null && GetRowFromElement(be) != null)
{
return true;
}
- DataTable table = GetTableSchemaForElement(rowElem);
+ DataTable table = GetTableSchemaForElement(rowElem)!;
DataColumnCollection columns = table.Columns;
int iColumn = 0;
}
// only mapped attrs are valid
- DataColumn schema = GetColumnSchemaForNode(rowElem, attr);
+ DataColumn? schema = GetColumnSchemaForNode(rowElem, attr);
if (schema == null)
{
return false;
}
// must have exactly one text node (XmlNodeType.Text) child
- XmlNode fc = attr.FirstChild;
+ XmlNode? fc = attr.FirstChild;
if (fc == null || fc.NodeType != XmlNodeType.Text || fc.NextSibling != null)
{
return false;
// check column elements
iColumn = 0;
- XmlNode n = rowElem.FirstChild;
+ XmlNode? n = rowElem.FirstChild;
for (; n != null; n = n.NextSibling)
{
// only elements can exist in radically structured data
{
return false;
}
- XmlElement e = n as XmlElement;
+ XmlElement? e = n as XmlElement;
// only checking for column mappings in this loop
if (GetRowFromElement(e) != null)
}
// element's must have schema to be radically structured
- DataColumn schema = GetColumnSchemaForNode(rowElem, e);
+ DataColumn? schema = GetColumnSchemaForNode(rowElem, e!);
if (schema == null)
{
return false;
}
// must have exactly one text node child
- XmlNode fc = e.FirstChild;
+ XmlNode? fc = e.FirstChild;
if (fc == null || fc.NodeType != XmlNodeType.Text || fc.NextSibling != null)
{
return false;
}
// element's must be regions in order to be radially structured
- DataRow row = GetRowFromElement((XmlElement)n);
+ DataRow? row = GetRowFromElement((XmlElement?)n);
if (row == null)
{
return false;
}
private void AddColumnSchema(DataColumn col)
{
- DataTable table = col.Table;
+ DataTable table = col.Table!;
object idTable = GetIdentity(table.EncodedTableName, table.Namespace);
object idColumn = GetIdentity(col.EncodedColumnName, col.Namespace);
- Hashtable columns = (Hashtable)_columnSchemaMap[idTable];
+ Hashtable? columns = (Hashtable?)_columnSchemaMap[idTable];
if (columns == null)
{
columns = new Hashtable();
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Data;
namespace System.Xml
internal interface IXmlDataVirtualNode
{
bool IsOnNode(XmlNode nodeToCheck);
- bool IsOnColumn(DataColumn col);
+ bool IsOnColumn(DataColumn? col);
bool IsInUse();
void OnFoliated(XmlNode foliatedNode);
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
#pragma warning disable 618 // ignore obsolete warning about XmlDataDocument
_currentNode = rowElement;
}
- internal override XmlNode CurrentNode => _currentNode;
+ internal override XmlNode? CurrentNode => _currentNode;
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal override bool Next()
{
- XmlNode nextNode;
+ XmlNode? nextNode;
ElementState oldState = _rowElement.ElementState;
// We do not want to cause any foliation w/ this iterator or use this iterator once the region was defoliated
if (nextNode != null)
{
_currentNode = nextNode;
+ Debug.Assert(CurrentNode != null);
// If we have been defoliated, we should have stayed that way
Debug.Assert((oldState == ElementState.Defoliated) ? (_rowElement.ElementState == ElementState.Defoliated) : true);
// Rollback foliation
return NextRight();
}
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal override bool NextRight()
{
// Make sure we do not get past the rowElement if we call NextRight on a just initialized iterator and rowElement has no children
if (_currentNode == _rowElement)
{
- _currentNode = null;
+ _currentNode = null!;
return false;
}
// We do not want to cause any foliation w/ this iterator or use this iterator once the region was defoliated
Debug.Assert(oldState != ElementState.None);
- XmlNode nextNode = _currentNode.NextSibling;
+ XmlNode? nextNode = _currentNode.NextSibling;
if (nextNode != null)
{
Debug.Assert((oldState == ElementState.Defoliated) ? (_rowElement.ElementState == ElementState.Defoliated) : true);
// Rollback foliation
_rowElement.ElementState = oldState;
+ Debug.Assert(CurrentNode != null);
return true;
}
// No next sibling, try the first sibling of from the parent chain
nextNode = _currentNode;
- while (nextNode != _rowElement && nextNode.NextSibling == null)
+ while (nextNode != _rowElement && nextNode!.NextSibling == null)
{
nextNode = nextNode.ParentNode;
}
if (nextNode == _rowElement)
{
- _currentNode = null;
+ _currentNode = null!;
// If we have been defoliated, we should have stayed that way
Debug.Assert((oldState == ElementState.Defoliated) ? (_rowElement.ElementState == ElementState.Defoliated) : true);
return false;
}
+ Debug.Assert(nextNode.NextSibling != null);
_currentNode = nextNode.NextSibling;
- Debug.Assert(_currentNode != null);
// If we have been defoliated, we should have stayed that way
Debug.Assert((oldState == ElementState.Defoliated) ? (_rowElement.ElementState == ElementState.Defoliated) : true);
// Rollback foliation
_rowElement.ElementState = oldState;
+ Debug.Assert(CurrentNode != null);
return true;
}
// Get the initial text value for the current node. You should be positioned on the node (element) for
// which to get the initial text value, not on the text node.
+ [MemberNotNullWhen(true, nameof(CurrentNode))]
internal bool NextInitialTextLikeNodes(out string value)
{
Debug.Assert(CurrentNode != null);
// We do not want to cause any foliation w/ this iterator or use this iterator once the region was defoliated
Debug.Assert(oldState != ElementState.None);
- XmlNode n = CurrentNode.FirstChild;
+ XmlNode? n = CurrentNode.FirstChild;
value = GetInitialTextFromNodes(ref n);
if (n == null)
{
return true;
}
- private static string GetInitialTextFromNodes(ref XmlNode n)
+ private static string GetInitialTextFromNodes(ref XmlNode? n)
{
- string value = null;
+ string? value = null;
if (n != null)
{
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Diagnostics;
#pragma warning disable 0618 // ignore obsolete warning about XmlDataDocument
private readonly XmlNode _nodeTop;
private XmlNode _currentNode;
- internal TreeIterator(XmlNode nodeTop) : base(((XmlDataDocument)(nodeTop.OwnerDocument)).Mapper)
+ internal TreeIterator(XmlNode nodeTop) : base(((XmlDataDocument)(nodeTop.OwnerDocument!)).Mapper)
{
Debug.Assert(nodeTop != null);
_nodeTop = nodeTop;
_currentNode = nodeTop;
}
- internal override XmlNode CurrentNode => _currentNode;
+ internal override XmlNode? CurrentNode => _currentNode;
internal override bool Next()
{
- XmlNode nextNode;
+ XmlNode? nextNode;
// Try to move to the first child
nextNode = _currentNode.FirstChild;
// Make sure we do not get past the nodeTop if we call NextRight on a just initialized iterator and nodeTop has no children
if (_currentNode == _nodeTop)
{
- _currentNode = null;
+ _currentNode = null!;
return false;
}
- XmlNode nextNode = _currentNode.NextSibling;
+ XmlNode? nextNode = _currentNode.NextSibling;
if (nextNode != null)
{
// No next sibling, try the first sibling of from the parent chain
nextNode = _currentNode;
- while (nextNode != _nodeTop && nextNode.NextSibling == null)
+ while (nextNode != _nodeTop && nextNode!.NextSibling == null)
{
nextNode = nextNode.ParentNode;
}
if (nextNode == _nodeTop)
{
- _currentNode = null;
+ _currentNode = null!;
return false;
}
+ Debug.Assert(nextNode.NextSibling != null);
_currentNode = nextNode.NextSibling;
- Debug.Assert(_currentNode != null);
return true;
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Data;
using System.Diagnostics;
using System.Xml.XPath;
private readonly WeakReference _owner; // Owner of this pointer (an DataDocumentXPathNavigator). When the associated DataDocumentXPathNavigator (the owner) goes away, this XPathNodePointer can go away as well.
private readonly XmlDataDocument _doc;
private XmlNode _node;
- private DataColumn _column;
+ private DataColumn? _column;
private bool _fOnValue;
- internal XmlBoundElement _parentOfNS;
+ internal XmlBoundElement? _parentOfNS;
internal static readonly int[] s_xmlNodeType_To_XpathNodeType_Map = CreateXmlNodeTypeToXpathNodeTypeMap();
internal const string StrReservedXmlns = "http://www.w3.org/2000/xmlns/";
internal const string StrReservedXml = "http://www.w3.org/XML/1998/namespace";
Array enumValues = Enum.GetValues(typeof(XmlNodeType));
for (int i = 0; i < enumValues.Length; i++)
{
- tempVal = (int)enumValues.GetValue(i);
+ tempVal = (int)enumValues.GetValue(i)!;
if (tempVal > max)
max = tempVal;
}
//the function can only be called on text like nodes.
Debug.Assert(XmlDataDocument.IsTextNode(node.NodeType));
XPathNodeType xnt = XPathNodeType.Whitespace;
- while (node != null)
+ XmlNode? n = node;
+ while (n != null)
{
- switch (node.NodeType)
+ switch (n.NodeType)
{
case XmlNodeType.Whitespace:
break;
default:
return xnt;
}
- node = _doc.SafeNextSibling(node);
+ n = _doc.SafeNextSibling(n);
}
return xnt;
}
{
}
- private XPathNodePointer(DataDocumentXPathNavigator owner, XmlDataDocument doc, XmlNode node, DataColumn c, bool bOnValue, XmlBoundElement parentOfNS)
+ private XPathNodePointer(DataDocumentXPathNavigator owner, XmlDataDocument doc, XmlNode node, DataColumn? c, bool bOnValue, XmlBoundElement? parentOfNS)
{
Debug.Assert(owner != null);
_owner = new WeakReference(owner);
}
}
- internal string Value
+ internal string? Value
{
get
{
return null;
else if (_column == null)
{
- string strRet = _node.Value;
+ string? strRet = _node.Value;
if (XmlDataDocument.IsTextNode(_node.NodeType))
{
//concatenate adjacent textlike nodes
- XmlNode parent = _node.ParentNode;
+ XmlNode? parent = _node.ParentNode;
if (parent == null)
return strRet;
- XmlNode n = _doc.SafeNextSibling(_node);
+ XmlNode? n = _doc.SafeNextSibling(_node);
while (n != null && XmlDataDocument.IsTextNode(n.NodeType))
{
strRet += n.Value;
}
else if (_column.ColumnMapping == MappingType.Attribute || _fOnValue)
{
- DataRow row = Row;
+ DataRow row = Row!;
DataRowVersion rowVersion = (row.RowState == DataRowState.Detached) ? DataRowVersion.Proposed : DataRowVersion.Current;
object value = row[_column, rowVersion];
if (!Convert.IsDBNull(value))
if (_node.NodeType == XmlNodeType.Document)
{
//document node's region should always be uncompressed
- XmlElement rootElem = ((XmlDocument)_node).DocumentElement;
+ XmlElement? rootElem = ((XmlDocument)_node).DocumentElement;
if (rootElem != null)
return rootElem.InnerText;
return string.Empty;
}
else
{
- DataRow row = Row;
+ DataRow row = Row!;
DataRowVersion rowVersion = (row.RowState == DataRowState.Detached) ? DataRowVersion.Proposed : DataRowVersion.Current;
object value = row[_column, rowVersion];
if (!Convert.IsDBNull(value))
{
RealFoliate();
XmlNode curNode = _node;
- XmlBoundElement curBoundElem = null;
- object colVal = null;
+ XmlBoundElement? curBoundElem = null;
+ object? colVal = null;
while (curNode != null)
{
curBoundElem = curNode as XmlBoundElement;
if (curBoundElem.ElementState == ElementState.Defoliated)
{
//if not foliated, going through the columns to get the xml:lang
- DataRow row = curBoundElem.Row;
+ DataRow row = curBoundElem.Row!;
foreach (DataColumn col in row.Table.Columns)
{
if (col.Prefix == "xml" && col.EncodedColumnName == "lang")
}
}
if (curNode.NodeType == XmlNodeType.Attribute)
- curNode = ((XmlAttribute)curNode).OwnerElement;
+ curNode = ((XmlAttribute)curNode).OwnerElement!;
else
- curNode = curNode.ParentNode;
+ curNode = curNode.ParentNode!;
}
return string.Empty;
}
}
- private XmlBoundElement GetRowElement()
+ private XmlBoundElement? GetRowElement()
{
- XmlBoundElement rowElem;
+ XmlBoundElement? rowElem;
if (_column != null)
{
- rowElem = _node as XmlBoundElement;
+ rowElem = (XmlBoundElement)_node;
Debug.Assert(rowElem != null);
Debug.Assert(rowElem.Row != null);
return rowElem;
return rowElem;
}
- private DataRow Row
+ private DataRow? Row
{
get
{
- XmlBoundElement rowElem = GetRowElement();
+ XmlBoundElement? rowElem = GetRowElement();
if (rowElem == null)
return null;
_fOnValue = false;
}
- private void MoveTo(XmlNode node, DataColumn column, bool fOnValue)
+ private void MoveTo(XmlNode node, DataColumn? column, bool fOnValue)
{
// Should not move outside of this document
Debug.Assert(node == _doc || node.OwnerDocument == _doc);
private int ColumnCount(DataRow row, bool fAttribute)
{
- DataColumn c = null;
+ DataColumn? c = null;
int count = 0;
while ((c = NextColumn(row, c, fAttribute)) != null)
{
if (_column == null && _node.NodeType == XmlNodeType.Element)
{
if (!IsFoliated(_node))
- return ColumnCount(Row, true);
+ return ColumnCount(Row!, true);
else
{
int nc = 0;
- foreach (XmlAttribute attr in _node.Attributes)
+ foreach (XmlAttribute attr in _node.Attributes!)
{
if (attr.NamespaceURI != StrReservedXmlns)
nc++;
}
}
- internal DataColumn NextColumn(DataRow row, DataColumn col, bool fAttribute)
+ internal DataColumn? NextColumn(DataRow row, DataColumn? col, bool fAttribute)
{
if (row.RowState == DataRowState.Deleted)
return null;
return null;
}
- internal DataColumn PreviousColumn(DataRow row, DataColumn col, bool fAttribute)
+ internal DataColumn? PreviousColumn(DataRow row, DataColumn? col, bool fAttribute)
{
if (row.RowState == DataRowState.Deleted)
return null;
{
if (!IsFoliated(_node))
{
- DataColumn c = null;
- while ((c = NextColumn(Row, c, true)) != null)
+ DataColumn? c = null;
+ while ((c = NextColumn(Row!, c, true)) != null)
{
if (c.EncodedColumnName == localName && c.Namespace == namespaceURI)
{
else
{
Debug.Assert(_node.Attributes != null);
- XmlNode n = _node.Attributes.GetNamedItem(localName, namespaceURI);
+ XmlNode? n = _node.Attributes.GetNamedItem(localName, namespaceURI);
if (n != null)
{
MoveTo(n, null, false);
}
if (!IsFoliated(_node))
{
- DataColumn c = _column;
- while ((c = NextColumn(Row, c, true)) != null)
+ DataColumn? c = _column;
+ while ((c = NextColumn(Row!, c, true)) != null)
{
if (c.Namespace != StrReservedXmlns)
{
{
if (bFirst)
{
- XmlAttributeCollection attrs = _node.Attributes;
+ XmlAttributeCollection attrs = _node.Attributes!;
foreach (XmlAttribute attr in attrs)
{
if (attr.NamespaceURI != StrReservedXmlns)
}
else
{
- XmlAttributeCollection attrs = ((XmlAttribute)_node).OwnerElement.Attributes;
+ XmlAttributeCollection attrs = ((XmlAttribute)_node).OwnerElement!.Attributes;
bool bFound = false;
foreach (XmlAttribute attr in attrs)
{
Debug.Assert(_column.ColumnMapping != MappingType.Attribute && _column.ColumnMapping != MappingType.Hidden);
return false;
}
- DataRow curRow = Row;
- DataColumn c = NextColumn(curRow, _column, false);
+ DataRow curRow = Row!;
+ DataColumn? c = NextColumn(curRow, _column, false);
while (c != null)
{
if (IsValidChild(_node, c))
}
c = NextColumn(curRow, c, false);
}
- XmlNode n = _doc.SafeFirstChild(_node);
+ XmlNode? n = _doc.SafeFirstChild(_node);
if (n != null)
{
MoveTo(n);
}
else
{
- XmlNode n = _node;
- XmlNode parent = _node.ParentNode;
+ XmlNode? n = _node;
+ XmlNode? parent = _node.ParentNode;
if (parent == null)
return false;
bool bTextLike = XmlDataDocument.IsTextNode(_node.NodeType);
{
if (_fOnValue)
return false;
- DataRow curRow = Row;
- DataColumn c = PreviousColumn(curRow, _column, false);
+ DataRow curRow = Row!;
+ DataColumn? c = PreviousColumn(curRow, _column, false);
while (c != null)
{
if (IsValidChild(_node, c))
}
else
{
- XmlNode n = _node;
- XmlNode parent = _node.ParentNode;
+ XmlNode? n = _node;
+ XmlNode? parent = _node.ParentNode;
if (parent == null)
return false;
bool bTextLike = XmlDataDocument.IsTextNode(_node.NodeType);
}
if (!IsFoliated(parent) && (parent is XmlBoundElement))
{
- DataRow row = ((XmlBoundElement)parent).Row;
+ DataRow? row = ((XmlBoundElement)parent).Row;
if (row != null)
{
- DataColumn c = PreviousColumn(row, null, false);
+ DataColumn? c = PreviousColumn(row, null, false);
if (c != null)
{
MoveTo(parent, c, _doc.IsTextOnly(c));
AssertValid();
if (_node != null)
{
- DataRow curRow = null;
- XmlNode parent = null;
+ DataRow? curRow = null;
+ XmlNode? parent = null;
if (_column != null)
{
curRow = Row;
//first check with the columns in the row
if (curRow != null)
{
- DataColumn c = NextColumn(curRow, null, false);
+ DataColumn? c = NextColumn(curRow, null, false);
while (c != null)
{
if (IsValidChild(_node, c))
}
}
//didn't find a valid column or maybe already Foliated, go through its children nodes
- XmlNode n = _doc.SafeFirstChild(parent);
+ XmlNode? n = _doc.SafeFirstChild(parent);
while (n != null)
{
if (IsValidChild(parent, n))
if (!IsFoliated(_node))
{
// find virtual column elements first
- DataRow curRow = Row;
- DataColumn c = NextColumn(curRow, null, false);
+ DataRow curRow = Row!;
+ DataColumn? c = NextColumn(curRow, null, false);
while (c != null)
{
if (IsValidChild(_node, c))
}
}
// look for anything
- XmlNode n = _doc.SafeFirstChild(_node);
+ XmlNode? n = _doc.SafeFirstChild(_node);
while (n != null)
{
if (IsValidChild(_node, n))
if (!IsFoliated(_node))
{
// find virtual column elements first
- DataRow curRow = Row;
- DataColumn c = NextColumn(curRow, null, false);
+ DataRow curRow = Row!;
+ DataColumn? c = NextColumn(curRow, null, false);
while (c != null)
{
if (IsValidChild(_node, c))
}
}
// look for anything
- XmlNode n = _doc.SafeFirstChild(_node);
+ XmlNode? n = _doc.SafeFirstChild(_node);
while (n != null)
{
if (IsValidChild(_node, n))
AssertValid();
if (NodeType == XPathNodeType.Namespace)
{
- MoveTo(_parentOfNS);
+ MoveTo(_parentOfNS!);
return true;
}
if (_node != null)
}
else
{
- XmlNode n = null;
+ XmlNode? n = null;
if (_node.NodeType == XmlNodeType.Attribute)
n = ((XmlAttribute)_node).OwnerElement;
else
return false;
}
- private XmlNode GetParent(XmlNode node)
+ private XmlNode? GetParent(XmlNode node)
{
XPathNodeType xnt = ConvertNodeType(node);
if (xnt == XPathNodeType.Namespace)
internal void MoveToRoot()
{
XmlNode node = _node;
- XmlNode parent = _node;
+ XmlNode? parent = _node;
while (parent != null)
{
node = parent;
private XmlNodeOrder CompareNamespacePosition(XPathNodePointer other)
{
- XPathNodePointer xp1 = Clone((DataDocumentXPathNavigator)(_owner.Target));
- XPathNodePointer xp2 = other.Clone((DataDocumentXPathNavigator)(other._owner.Target));
+ XPathNodePointer xp1 = Clone((DataDocumentXPathNavigator)(_owner.Target!));
+ XPathNodePointer xp2 = other.Clone((DataDocumentXPathNavigator)(other._owner.Target!));
while (xp1.MoveToNextNamespace(XPathNamespaceScope.All))
{
if (xp1.IsSamePosition(xp2))
{
depth = 0;
XmlNode curNode = node;
- XmlNode parent = ((curNode.NodeType == XmlNodeType.Attribute) ? (((XmlAttribute)curNode).OwnerElement) : (curNode.ParentNode));
+ XmlNode? parent = ((curNode.NodeType == XmlNodeType.Attribute) ? (((XmlAttribute)curNode).OwnerElement) : (curNode.ParentNode));
for (; parent != null; depth++)
{
curNode = parent;
if (IsSamePosition(other))
return XmlNodeOrder.Same;
- XmlNode curNode1 = null, curNode2 = null;
+ XmlNode? curNode1 = null, curNode2 = null;
//deal with namespace node first
if (NodeType == XPathNodeType.Namespace && other.NodeType == XPathNodeType.Namespace)
return XmlNodeOrder.Before;
}
- XmlNode parent1 = GetParent(curNode1);
- XmlNode parent2 = GetParent(curNode2);
- XmlNode nextNode = null;
+ XmlNode? parent1 = GetParent(curNode1!);
+ XmlNode? parent2 = GetParent(curNode2!);
+ XmlNode? nextNode = null;
while (parent1 != null && parent2 != null)
{
if (parent1 == parent2)
return XmlNodeOrder.Unknown;
}
- internal XmlNode Node
+ internal XmlNode? Node
{
get
{
if (_node == null)
return null;
- XmlBoundElement rowElem = GetRowElement();
+ XmlBoundElement? rowElem = GetRowElement();
if (rowElem != null)
{
bool wasFoliationEnabled = _doc.IsFoliationEnabled;
return nodeToCheck == _node;
}
- bool IXmlDataVirtualNode.IsOnColumn(DataColumn col)
+ bool IXmlDataVirtualNode.IsOnColumn(DataColumn? col)
{
RealFoliate();
return col == _column;
Debug.Assert(_column != null);
- XmlNode n = null;
+ XmlNode? n = null;
if (_doc.IsTextOnly(_column))
n = _node.FirstChild;
{
if (_column.ColumnMapping == MappingType.Attribute)
{
- n = _node.Attributes.GetNamedItem(_column.EncodedColumnName, _column.Namespace);
+ n = _node.Attributes!.GetNamedItem(_column.EncodedColumnName, _column.Namespace);
}
else
{
//The function only helps to find out if there is a namespace declaration of given name is defined on the given node
//It will not check the ancestor of the given node.
- private string GetNamespace(XmlBoundElement be, string name)
+ private string? GetNamespace(XmlBoundElement be, string name)
{
if (be == null)
return null;
- XmlAttribute attr = null;
+ XmlAttribute? attr = null;
if (be.IsFoliated)
{
attr = be.GetAttributeNode(name, StrReservedXmlns);
}
else
{ //defoliated so that we need to search through its column
- DataRow curRow = be.Row;
+ DataRow? curRow = be.Row;
if (curRow == null)
return null;
//going through its attribute columns
- DataColumn curCol = PreviousColumn(curRow, null, true);
+ DataColumn? curCol = PreviousColumn(curRow, null, true);
while (curCol != null)
{
if (curCol.Namespace == StrReservedXmlns)
if (name != null && name.Length == 0)
name = "xmlns";
RealFoliate();
- XmlNode node = _node;
+ XmlNode? node = _node;
XmlNodeType nt = node.NodeType;
- string retVal = null;
+ string? retVal = null;
while (node != null)
{
//first identify an element node in the ancestor + itself
if (node != null)
{
//must be element node
- retVal = GetNamespace((XmlBoundElement)node, name);
+ retVal = GetNamespace((XmlBoundElement)node, name!);
if (retVal != null)
return retVal;
//didn't find it, try the next parentnode
if (attrName != null && attrName.Length == 0)
attrName = "xmlns";
RealFoliate();
- XmlNode node = _node;
- XmlAttribute attr = null;
- XmlBoundElement be = null;
+ XmlNode? node = _node;
+ XmlAttribute? attr = null;
+ XmlBoundElement? be = null;
while (node != null)
{
//check current element node
}
else
{//defoliated so that we need to search through its column
- DataRow curRow = be.Row;
+ DataRow? curRow = be.Row;
if (curRow == null)
return false;
//going through its attribute columns
- DataColumn curCol = PreviousColumn(curRow, null, true);
+ DataColumn? curCol = PreviousColumn(curRow, null, true);
while (curCol != null)
{
if (curCol.Namespace == StrReservedXmlns && curCol.ColumnName == name)
//the function will find the next namespace node on the given bound element starting with the given column or attribute
// whether to use column or attribute depends on if the bound element is foliated or not.
- private bool MoveToNextNamespace(XmlBoundElement be, DataColumn col, XmlAttribute curAttr)
+ private bool MoveToNextNamespace(XmlBoundElement? be, DataColumn? col, XmlAttribute? curAttr)
{
if (be != null)
{
if (be.IsFoliated)
{
XmlAttributeCollection attrs = be.Attributes;
- XmlAttribute attr = null;
+ XmlAttribute? attr = null;
bool bFound = false;
if (curAttr == null)
bFound = true; //the first namespace will be the one
}
else
{//defoliated so that we need to search through its column
- DataRow curRow = be.Row;
+ DataRow? curRow = be.Row;
if (curRow == null)
return false;
//going through its attribute columns
- DataColumn curCol = PreviousColumn(curRow, col, true);
+ DataColumn? curCol = PreviousColumn(curRow, col, true);
while (curCol != null)
{
if (curCol.Namespace == StrReservedXmlns && !DuplicateNS(be, curCol.ColumnName))
//only need to check with _node, even if _column is not null and its mapping type is element, it can't have attributes
if (_parentOfNS == null)
return false;
- XmlNode node = _node;
- XmlBoundElement be = null;
+ XmlNode? node = _node;
+ XmlBoundElement? be = null;
while (node != null)
{
be = node as XmlBoundElement;
{
if (_parentOfNS == null || endElem == null)
return false;
- XmlBoundElement be = _parentOfNS;
- XmlNode node = null;
+ XmlBoundElement? be = _parentOfNS;
+ XmlNode? node = null;
while (be != null && be != endElem)
{
if (GetNamespace(be, lname) != null)
{
RealFoliate();
Debug.Assert(_parentOfNS != null);
- XmlNode node = _node;
+ XmlNode? node = _node;
//first check within the same boundelement
if (_column != null)
{
Debug.Assert(_column.Namespace == StrReservedXmlns);
if (namespaceScope == XPathNamespaceScope.Local && _parentOfNS != _node) //already outside scope
return false;
- XmlBoundElement be = _node as XmlBoundElement;
+ XmlBoundElement? be = _node as XmlBoundElement;
Debug.Assert(be != null);
- DataRow curRow = be.Row;
+ DataRow? curRow = be.Row;
Debug.Assert(curRow != null);
- DataColumn curCol = PreviousColumn(curRow, _column, true);
+ DataColumn? curCol = PreviousColumn(curRow, _column, true);
while (curCol != null)
{
if (curCol.Namespace == StrReservedXmlns)
while (node != null)
{
//try the namespace attributes from the same element
- XmlBoundElement be = node as XmlBoundElement;
+ XmlBoundElement? be = node as XmlBoundElement;
if (MoveToNextNamespace(be, null, null))
return true;
//no more namespace attribute under the same element
if (_column != null)
{
// We must be on a de-foliated region
- XmlBoundElement rowElem = _node as XmlBoundElement;
+ XmlBoundElement? rowElem = _node as XmlBoundElement;
Debug.Assert(rowElem != null);
- DataRow row = rowElem.Row;
+ DataRow? row = rowElem.Row;
Debug.Assert(row != null);
// We cannot be on a column for which the value is DBNull
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Data;
using System.Diagnostics;
using System.Threading;
internal sealed class XmlBoundElement : XmlElement
{
- private DataRow _row;
+ private DataRow? _row;
private ElementState _state;
internal XmlBoundElement(string prefix, string localName, string namespaceURI, XmlDocument doc) : base(prefix, localName, namespaceURI, doc)
public override bool HasAttributes => Attributes.Count > 0;
- public override XmlNode FirstChild
+ public override XmlNode? FirstChild
{
get
{
}
}
- internal XmlNode SafeFirstChild => base.FirstChild;
+ internal XmlNode? SafeFirstChild => base.FirstChild;
- public override XmlNode LastChild
+ public override XmlNode? LastChild
{
get
{
}
}
- public override XmlNode PreviousSibling
+ public override XmlNode? PreviousSibling
{
get
{
- XmlNode prev = base.PreviousSibling;
+ XmlNode? prev = base.PreviousSibling;
if (prev == null)
{
- XmlBoundElement parent = ParentNode as XmlBoundElement;
+ XmlBoundElement? parent = ParentNode as XmlBoundElement;
if (parent != null)
{
parent.AutoFoliate();
}
}
- internal XmlNode SafePreviousSibling => base.PreviousSibling;
+ internal XmlNode? SafePreviousSibling => base.PreviousSibling;
- public override XmlNode NextSibling
+ public override XmlNode? NextSibling
{
get
{
- XmlNode next = base.NextSibling;
+ XmlNode? next = base.NextSibling;
if (next == null)
{
- XmlBoundElement parent = ParentNode as XmlBoundElement;
+ XmlBoundElement? parent = ParentNode as XmlBoundElement;
if (parent != null)
{
parent.AutoFoliate();
}
}
- internal XmlNode SafeNextSibling => base.NextSibling;
+ internal XmlNode? SafeNextSibling => base.NextSibling;
public override bool HasChildNodes
{
}
}
- public override XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
+ public override XmlNode? InsertBefore(XmlNode newChild, XmlNode? refChild)
{
AutoFoliate();
return base.InsertBefore(newChild, refChild);
}
- public override XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
+ public override XmlNode? InsertAfter(XmlNode newChild, XmlNode? refChild)
{
AutoFoliate();
return base.InsertAfter(newChild, refChild);
return base.ReplaceChild(newChild, oldChild);
}
- public override XmlNode AppendChild(XmlNode newChild)
+ public override XmlNode? AppendChild(XmlNode newChild)
{
AutoFoliate();
return base.AppendChild(newChild);
internal void RemoveAllChildren()
{
- XmlNode child = FirstChild;
- XmlNode sibling = null;
+ XmlNode? child = FirstChild;
+ XmlNode? sibling = null;
while (child != null)
{
}
}
- internal DataRow Row
+ internal DataRow? Row
{
get { return _row; }
set { _row = value; }
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml.XPath;
ArrayList al = new ArrayList();
foreach (DictionaryEntry entry in _pointers)
{
- IXmlDataVirtualNode temp = (IXmlDataVirtualNode)(entry.Value);
+ IXmlDataVirtualNode? temp = (IXmlDataVirtualNode?)(entry.Value);
Debug.Assert(temp != null);
if (!temp.IsInUse())
al.Add(temp);
}
for (int i = 0; i < al.Count; i++)
{
- _pointers.Remove(al[i]);
+ _pointers.Remove(al[i]!);
}
_countAddPointer = 0;
}
internal void AssertPointerPresent(IXmlDataVirtualNode pointer)
{
#if DEBUG
- object val = _pointers[pointer];
+ object? val = _pointers[pointer];
if (val != (object)pointer)
Debug.Fail("Pointer not present");
#endif
// - ds.ReadXmlData(); // ds is now filled, however doc has no content (since there were no listeners for the new created DataRow's)
// We can set-up listeners and track each change in schema, but it is more perf-friendly to do it laizily, all at once, when the first DataRow is created
// (we rely on the fact that DataRowCreated is a DataSet wide event, rather than a DataTable event)
+ [MemberNotNull(nameof(_dataSet))]
private void AttachDataSet(DataSet ds)
{
// You should not have already an associated dataset
// after loading, all detached DataRows are synchronized with the xml tree and inserted to their tables
// or after setting the innerxml, synchronize the rows and if created new and detached, will be inserted.
- internal void SyncRows(DataRow parentRow, XmlNode node, bool fAddRowsToTable)
+ internal void SyncRows(DataRow? parentRow, XmlNode node, bool fAddRowsToTable)
{
- XmlBoundElement be = node as XmlBoundElement;
+ XmlBoundElement? be = node as XmlBoundElement;
if (be != null)
{
- DataRow r = be.Row;
+ DataRow? r = be.Row;
if (r != null && be.ElementState == ElementState.Defoliated)
return; //no need of syncRow
}
// Attach all rows from children nodes
- for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
+ for (XmlNode? child = node.FirstChild; child != null; child = child.NextSibling)
SyncRows(parentRow, child, fAddRowsToTable);
}
// Synchronize the rows and if created new and detached, will be inserted.
internal void SyncTree(XmlNode node)
{
- XmlBoundElement be = null;
+ XmlBoundElement? be = null;
_mapper.GetRegion(node, out be);
- DataRow parentRow = null;
+ DataRow? parentRow = null;
bool fAddRowsToTable = IsConnected(node);
if (be != null)
{
- DataRow r = be.Row;
+ DataRow? r = be.Row;
if (r != null && be.ElementState == ElementState.Defoliated)
return; //no need of syncRow
}
// Attach all rows from children nodes
- for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
+ for (XmlNode? child = node.FirstChild; child != null; child = child.NextSibling)
SyncRows(parentRow, child, fAddRowsToTable);
}
/// Creates an element with the specified Prefix, LocalName, and
/// NamespaceURI.
/// </summary>
- public override XmlElement CreateElement(string prefix, string localName, string namespaceURI)
+ public override XmlElement CreateElement(string? prefix, string localName, string? namespaceURI)
{
// There are three states for the document:
// - special listeners ON, no permananent listeners: this is when the data doc was created w/o any dataset, and the 1st time a new row/element
if (col.ColumnMapping != MappingType.Hidden)
SetRowValueToNull(row, col);
}
- XmlBoundElement be = row.Element;
+ XmlBoundElement? be = row.Element;
Debug.Assert(be != null);
be.Prefix = prefix;
return be;
// drop all attributes
rowElem.RemoveAllAttributes();
- XmlNode node = rowElem.FirstChild;
+ XmlNode? node = rowElem.FirstChild;
while (node != null)
{
- XmlNode next = node.NextSibling;
+ XmlNode? next = node.NextSibling;
- XmlBoundElement be = node as XmlBoundElement;
+ XmlBoundElement? be = node as XmlBoundElement;
if (be != null && be.Row != null)
break;
private XmlElement EnsureDocumentElement()
{
- XmlElement docelem = DocumentElement;
+ XmlElement? docelem = DocumentElement;
if (docelem == null)
{
string docElemName = XmlConvert.EncodeLocalName(DataSet.DataSetName);
}
private XmlElement EnsureNonRowDocumentElement()
{
- XmlElement docElem = DocumentElement;
+ XmlElement? docElem = DocumentElement;
if (docElem == null)
return EnsureDocumentElement();
- DataRow rowDocElem = GetRowFromElement(docElem);
+ DataRow? rowDocElem = GetRowFromElement(docElem);
if (rowDocElem == null)
return docElem;
Debug.Assert(GetRowFromElement(DocumentElement) != null);
// Remove the DocumentElement and create a new one
- XmlElement oldDocElem = DocumentElement;
+ XmlElement oldDocElem = DocumentElement!;
RemoveChild(oldDocElem);
XmlElement docElem = EnsureDocumentElement();
docElem.AppendChild(oldDocElem);
{
foreach (DataRow r in row.GetChildRows(dr))
{
- XmlElement childElem = r.Element;
+ XmlElement? childElem = r.Element;
// childElem can be null when we create XML from DataSet (XmlDataDocument( DataSet ) is called) and we insert rowElem of the parentRow before
// we insert the rowElem of children rows.
if (childElem != null)
#endif
if (childElem.ParentNode != rowElement)
{
- childElem.ParentNode.RemoveChild(childElem);
+ childElem.ParentNode!.RemoveChild(childElem);
rowElement.AppendChild(childElem);
}
#if DEBUG
{
if (newState == ElementState.StrongFoliation && node.Row == null)
{
- XmlBoundElement rowElem;
+ XmlBoundElement? rowElem;
ElementState rowElemState = ElementState.None;
if (_mapper.GetRegion(node, out rowElem))
{
try
{
- XmlNode priorNode = null;
+ XmlNode? priorNode = null;
DataRow row = node.Row;
// create new attrs & elements for row
}
else
{
- XmlNode newNode = null;
+ XmlNode? newNode = null;
if (col.ColumnMapping == MappingType.Element)
{
newNode = new XmlBoundElement(string.Empty, col.EncodedColumnName, col.Namespace, this);
}
//Determine best radical insert position for inserting column elements
- private XmlNode GetColumnInsertAfterLocation(DataRow row, DataColumn col, XmlBoundElement rowElement)
+ private XmlNode? GetColumnInsertAfterLocation(DataRow row, DataColumn col, XmlBoundElement rowElement)
{
- XmlNode prev = null;
- XmlNode node = null;
+ XmlNode? prev = null;
+ XmlNode? node = null;
// text only columns appear first
if (IsTextOnly(col))
// insert location must be before any non-element nodes
if (node.NodeType != XmlNodeType.Element)
break;
- XmlElement e = node as XmlElement;
+ XmlElement? e = node as XmlElement;
// insert location must be before any non-mapped elements or separate regions
if (_mapper.GetRowFromElement(e) != null)
break;
- object schema = _mapper.GetColumnSchemaForNode(rowElement, node);
+ object? schema = _mapper.GetColumnSchemaForNode(rowElement, node);
if (schema == null || !(schema is DataColumn))
break;
return list;
}
- private DataRow GetNestedParent(DataRow row)
+ private DataRow? GetNestedParent(DataRow row)
{
- DataRelation relation = GetNestedParentRelation(row);
+ DataRelation? relation = GetNestedParentRelation(row);
if (relation != null)
return row.GetParentRow(relation);
return null;
}
- private static DataRelation GetNestedParentRelation(DataRow row)
+ private static DataRelation? GetNestedParentRelation(DataRow row)
{
DataRelation[] relations = row.Table.NestedParentRelations;
if (relations.Length == 0)
return relations[0];
}
- private DataColumn GetTextOnlyColumn(DataRow row)
+ private DataColumn? GetTextOnlyColumn(DataRow row)
{
#if DEBUG
{
/// <summary>
/// Retrieves the DataRow associated with the specified XmlElement.
/// </summary>
- public DataRow GetRowFromElement(XmlElement e)
+ public DataRow? GetRowFromElement(XmlElement? e)
{
return _mapper.GetRowFromElement(e);
}
- private XmlNode GetRowInsertBeforeLocation(DataRow row, XmlElement rowElement, XmlNode parentElement)
+ private XmlNode? GetRowInsertBeforeLocation(DataRow row, XmlElement rowElement, XmlNode parentElement)
{
DataRow refRow = row;
int i = 0;
break;
pos = i;
- DataRow parentRow = GetNestedParent(row);
+ DataRow? parentRow = GetNestedParent(row);
for (i = pos + 1; i < row.Table.Rows.Count; i++)
{
refRow = row.Table.Rows[i];
/// </summary>
public XmlElement GetElementFromRow(DataRow r)
{
- XmlBoundElement be = r.Element;
+ XmlBoundElement? be = r.Element;
Debug.Assert(be != null);
return be;
}
{
if (_pointers.Count > 0)
{
- object pointer = null;
+ object? pointer = null;
foreach (DictionaryEntry entry in _pointers)
{
pointer = entry.Value;
dp.MoveToOwnerElement();
if (dp.MoveToAttribute(i))
{
- newNode.Attributes.Append((XmlAttribute)CloneTreeInternal(dp));
+ newNode.Attributes!.Append((XmlAttribute)CloneTreeInternal(dp));
}
}
//for the nodes without value and have no children
XmlNodeType.DocumentFragment => CreateDocumentFragment(),
XmlNodeType.DocumentType => CreateDocumentType(dp.Name, dp.PublicId, dp.SystemId, dp.InternalSubset),
- XmlNodeType.XmlDeclaration => CreateXmlDeclaration(dp.Version, dp.Encoding, dp.Standalone),
+ XmlNodeType.XmlDeclaration => CreateXmlDeclaration(dp.Version!, dp.Encoding, dp.Standalone),
//for the nodes with value but no children
XmlNodeType.Text => CreateTextNode(dp.Value),
XmlNodeType.CDATA => CreateCDataSection(dp.Value),
- XmlNodeType.ProcessingInstruction => CreateProcessingInstruction(dp.Name, dp.Value),
+ XmlNodeType.ProcessingInstruction => CreateProcessingInstruction(dp.Name, dp.Value!),
XmlNodeType.Comment => CreateComment(dp.Value),
XmlNodeType.Whitespace => CreateWhitespace(dp.Value),
XmlNodeType.SignificantWhitespace => CreateSignificantWhitespace(dp.Value),
}
// load all data from tree structre into datarows
- private void LoadRows(XmlBoundElement rowElem, XmlNode node)
+ private void LoadRows(XmlBoundElement? rowElem, XmlNode node)
{
Debug.Assert(node != null);
- XmlBoundElement be = node as XmlBoundElement;
+ XmlBoundElement? be = node as XmlBoundElement;
if (be != null)
{
- DataTable dt = _mapper.SearchMatchingTableSchema(rowElem, be);
+ DataTable? dt = _mapper.SearchMatchingTableSchema(rowElem, be);
if (dt != null)
{
- DataRow r = GetRowFromElement(be);
+ DataRow? r = GetRowFromElement(be);
Debug.Assert(r == null);
// If the rowElement was just created and has an un-initialized
if (be.ElementState == ElementState.None)
}
}
// recurse down for children
- for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
+ for (XmlNode? child = node.FirstChild; child != null; child = child.NextSibling)
LoadRows(rowElem, child);
}
OnNewRow(row);
}
- internal void OnClearCalled(object oDataSet, DataTable table)
+ internal void OnClearCalled(object oDataSet, DataTable? table)
{
throw new NotSupportedException(SR.DataDom_NotSupport_Clear);
}
ForceFoliation(rowElement, AutoFoliationState);
Debug.Assert(rowElement != null);
- DataRow rowDocElem = GetRowFromElement(DocumentElement);
+ DataRow? rowDocElem = GetRowFromElement(DocumentElement);
if (rowDocElem != null)
{
- DataRow parentRow = GetNestedParent(row);
+ DataRow? parentRow = GetNestedParent(row);
if (parentRow == null)
DemoteDocumentElement();
}
{
if (_pointers.Count > 0)
{
- object pointer = null;
+ object? pointer = null;
foreach (DictionaryEntry entry in _pointers)
{
pointer = entry.Value;
{
value = string.Empty;
//make sure that rowElement has Attribute xsi:nil and its value is true
- XmlAttribute attr = rowElement.GetAttributeNode(XSI_NIL);
+ XmlAttribute? attr = rowElement.GetAttributeNode(XSI_NIL);
if (attr == null)
{
attr = CreateAttribute(XSI, Keywords.XSI_NIL, Keywords.XSINS);
else
{
//make sure that if rowElement has Attribute xsi:nil, its value is false
- XmlAttribute attr = rowElement.GetAttributeNode(XSI_NIL);
+ XmlAttribute? attr = rowElement.GetAttributeNode(XSI_NIL);
if (attr != null)
attr.Value = Keywords.FALSE;
}
{
if (Convert.IsDBNull(value))
{
- attr.OwnerElement.Attributes.Remove(attr);
+ attr.OwnerElement!.Attributes.Remove(attr);
}
else
{
bool fMore = iter.Next();
while (fMore)
{
- if (iter.CurrentNode.NodeType == XmlNodeType.Element)
+ if (iter.CurrentNode!.NodeType == XmlNodeType.Element)
{
XmlElement e = (XmlElement)iter.CurrentNode;
Debug.Assert(e != null);
//we should skip the subregion
- XmlBoundElement be = e as XmlBoundElement;
+ XmlBoundElement? be = e as XmlBoundElement;
if (be != null && be.Row != null)
{
fMore = iter.NextRight(); //skip over the sub-region
{
PromoteNonValueChildren(e);
fMore = iter.NextRight();
- e.ParentNode.RemoveChild(e);
+ e.ParentNode!.RemoveChild(e);
// keep looking for more matching elements
continue;
}
{
ReplaceInitialChildText(e, col.ConvertObjectToXml(value));
//make sure that if the Element has Attribute xsi:nil, its value is false
- XmlAttribute attr = e.GetAttributeNode(XSI_NIL);
+ XmlAttribute? attr = e.GetAttributeNode(XSI_NIL);
if (attr != null)
attr.Value = Keywords.FALSE;
// no need to look any further.
XmlElement newElem = new XmlBoundElement(string.Empty, col.EncodedColumnName, col.Namespace, this);
newElem.AppendChild(CreateTextNode(col.ConvertObjectToXml(value)));
- XmlNode elemBefore = GetColumnInsertAfterLocation(row, col, rowElement);
+ XmlNode? elemBefore = GetColumnInsertAfterLocation(row, col, rowElement);
if (elemBefore != null)
{
rowElement.InsertAfter(newElem, elemBefore);
}
lblDoNestedRelationSync:
// Change the XML to conform to the (potentially) change in parent nested relation
- DataRelation relation = GetNestedParentRelation(row);
+ DataRelation? relation = GetNestedParentRelation(row);
if (relation != null)
{
Debug.Assert(relation.ChildTable == row.Table);
try
{
DataRow row = args.Row;
- DataColumn col = args.Column;
+ DataColumn? col = args.Column;
if (row.RowState == DataRowState.Detached)
{
- XmlBoundElement be = row.Element;
+ XmlBoundElement? be = row.Element;
Debug.Assert(be != null);
if (be.IsFoliated)
{
// Need to sync changes from ROM to DOM
- OnColumnValueChanged(row, col, be);
+ OnColumnValueChanged(row, col!, be);
}
}
}
// but there will be multiple ROM events
if (_columnChangeList.Count > 0)
{
- if (((DataColumn)(_columnChangeList[0])).Table == row.Table)
+ if (((DataColumn)(_columnChangeList[0]!)).Table == row.Table)
{
foreach (DataColumn c in _columnChangeList)
OnColumnValueChanged(row, c, rowElement);
DemoteDocumentElement();
PromoteInnerRegions(rowElement);
- rowElement.ParentNode.RemoveChild(rowElement);
+ rowElement.ParentNode!.RemoveChild(rowElement);
}
private void OnDeletingRow(DataRow row, XmlBoundElement rowElement)
{
foreach (DictionaryEntry entry in _pointers)
{
- object pointer = entry.Value;
+ object? pointer = entry.Value;
Debug.Assert(pointer != null);
((IXmlDataVirtualNode)pointer).OnFoliated(node);
}
// You should never get here in regular cases
}
- private DataColumn FindAssociatedParentColumn(DataRelation relation, DataColumn childCol)
+ private DataColumn? FindAssociatedParentColumn(DataRelation relation, DataColumn childCol)
{
DataColumn[] columns = relation.ChildKey.ColumnsReference;
for (int i = 0; i < columns.Length; i++)
}
// Change the childElement position in the tree to conform to the parent nested relationship in ROM
- private void OnNestedParentChange(DataRow child, XmlBoundElement childElement, DataColumn childCol)
+ private void OnNestedParentChange(DataRow child, XmlBoundElement childElement, DataColumn? childCol)
{
Debug.Assert(child.Element == childElement && childElement.Row == child);
// This function is (and s/b) called as a result of ROM changes, therefore XML changes done here should not be sync-ed to ROM
// In order to check that this move does not change the connected/disconnected state of the node
bool fChildElementConnected = IsConnected(childElement);
#endif
- DataRow parentRowInTree;
+ DataRow? parentRowInTree;
if (childElement == DocumentElement || childElement.ParentNode == null)
parentRowInTree = null;
else
parentRowInTree = GetRowFromElement((XmlElement)childElement.ParentNode);
- DataRow parentRowInRelation = GetNestedParent(child);
+ DataRow? parentRowInRelation = GetNestedParent(child!);
if (parentRowInTree != parentRowInRelation)
{
else
{
// no parent? Maybe the parentRow is during changing or childCol is the ID is set to null ( detached from the parent row ).
- DataRelation relation = GetNestedParentRelation(child);
+ DataRelation? relation = GetNestedParentRelation(child!);
if (childCol == null || relation == null || Convert.IsDBNull(child[childCol]))
{
EnsureNonRowDocumentElement().AppendChild(childElement);
}
else
{
- DataColumn colInParent = FindAssociatedParentColumn(relation, childCol);
+ DataColumn? colInParent = FindAssociatedParentColumn(relation, childCol);
Debug.Assert(colInParent != null);
- object comparedValue = colInParent.ConvertValue(child[childCol]);
- if (parentRowInTree._tempRecord != -1 && colInParent.CompareValueTo(parentRowInTree._tempRecord, comparedValue) != 0)
+ object? comparedValue = colInParent.ConvertValue(child[childCol]);
+ if (parentRowInTree!._tempRecord != -1 && colInParent.CompareValueTo(parentRowInTree._tempRecord, comparedValue) != 0)
{
EnsureNonRowDocumentElement().AppendChild(childElement);
}
try
{
// okay to allow text node value changes when bound.
- XmlBoundElement rowElement = null;
+ XmlBoundElement? rowElement = null;
Debug.Assert(DataSet.EnforceConstraints == false);
try
{
// Handle both new node inserted and 2nd part of a move operation.
- XmlNode node = args.Node;
- XmlNode oldParent = args.OldParent;
- XmlNode newParent = args.NewParent;
+ XmlNode node = args.Node!;
+ XmlNode? oldParent = args.OldParent;
+ XmlNode? newParent = args.NewParent;
// The code bellow assumes a move operation is fired by DOM in 2 steps: a Remvoe followed by an Insert - this is the 2nd part, the Insert.
Debug.Assert(oldParent == null);
try
{
- XmlNode node = args.Node;
- XmlNode oldParent = args.OldParent;
+ XmlNode node = args.Node!;
+ XmlNode? oldParent = args.OldParent;
Debug.Assert(args.NewParent == null);
if (IsConnected(oldParent))
}
// Node was removed from connected tree to disconnected tree
- private void OnNodeRemovedFromTree(XmlNode node, XmlNode oldParent)
+ private void OnNodeRemovedFromTree(XmlNode node, XmlNode? oldParent)
{
- XmlBoundElement oldRowElem;
+ XmlBoundElement? oldRowElem;
// Synchronize values from old region
if (_mapper.GetRegion(oldParent, out oldRowElem))
SynchronizeRowFromRowElement(oldRowElem);
// Disconnect all regions, starting w/ node (if it is a row-elem)
- XmlBoundElement rowElem = node as XmlBoundElement;
+ XmlBoundElement? rowElem = node as XmlBoundElement;
if (rowElem != null && rowElem.Row != null)
EnsureDisconnectedDataRow(rowElem);
TreeIterator iter = new TreeIterator(node);
for (bool fMore = iter.NextRowElement(); fMore; fMore = iter.NextRowElement())
{
- rowElem = (XmlBoundElement)(iter.CurrentNode);
+ rowElem = (XmlBoundElement)(iter.CurrentNode!);
EnsureDisconnectedDataRow(rowElem);
}
AssertNonLiveRows(node);
}
// Node was removed from the disconnected tree to disconnected tree
- private void OnNodeRemovedFromFragment(XmlNode node, XmlNode oldParent)
+ private void OnNodeRemovedFromFragment(XmlNode node, XmlNode? oldParent)
{
- XmlBoundElement oldRowElem;
+ XmlBoundElement? oldRowElem;
if (_mapper.GetRegion(oldParent, out oldRowElem))
{
// Sync the old region if it is not deleted
- DataRow row = oldRowElem.Row;
+ DataRow row = oldRowElem.Row!;
// Since the old region was disconnected, then the row can be only Deleted or Detached
Debug.Assert(!IsRowLive(row));
- if (oldRowElem.Row.RowState == DataRowState.Detached)
+ if (oldRowElem.Row!.RowState == DataRowState.Detached)
SynchronizeRowFromRowElement(oldRowElem);
}
// Need to set nested for the sub-regions (if node is a row-elem, we need to set it just for itself)
- XmlBoundElement be = node as XmlBoundElement;
+ XmlBoundElement? be = node as XmlBoundElement;
if (be != null && be.Row != null)
{
Debug.Assert(!IsRowLive(be.Row));
TreeIterator iter = new TreeIterator(node);
for (bool fMore = iter.NextRowElement(); fMore; fMore = iter.NextRightRowElement())
{
- XmlBoundElement rowElemChild = (XmlBoundElement)(iter.CurrentNode);
+ XmlBoundElement rowElemChild = (XmlBoundElement)(iter.CurrentNode!);
SetNestedParentRegion(rowElemChild, null);
}
}
try
{
DataRow row = args.Row;
- XmlBoundElement rowElement = row.Element;
+ XmlBoundElement? rowElement = row.Element;
// We should have an associated row-elem created when the DataRow was created (or at the load time)
Debug.Assert(rowElement != null);
break;
case DataRowState.Added:
- rowElement.ParentNode.RemoveChild(rowElement);
+ rowElement.ParentNode!.RemoveChild(rowElement);
break;
case DataRowState.Modified:
}
}
- private void OnDataSetPropertyChanging(object oDataSet, PropertyChangedEventArgs args)
+ private void OnDataSetPropertyChanging(object? oDataSet, PropertyChangedEventArgs args)
{
if (args.PropertyName == "DataSetName")
throw new InvalidOperationException(SR.DataDom_DataSetNameChange);
}
- private void OnColumnPropertyChanging(object oColumn, PropertyChangedEventArgs args)
+ private void OnColumnPropertyChanging(object? oColumn, PropertyChangedEventArgs args)
{
if (args.PropertyName == "ColumnName")
throw new InvalidOperationException(SR.DataDom_ColumnNameChange);
if (args.PropertyName == "ColumnMapping")
throw new InvalidOperationException(SR.DataDom_ColumnMappingChange);
}
- private void OnTablePropertyChanging(object oTable, PropertyChangedEventArgs args)
+ private void OnTablePropertyChanging(object? oTable, PropertyChangedEventArgs args)
{
if (args.PropertyName == "TableName")
throw new InvalidOperationException(SR.DataDom_TableNameChange);
throw new InvalidOperationException(SR.DataDom_DataSetNestedRelationsChange);
// If Add and Remove, we should already been throwing if .Nested == false
- Debug.Assert(!(args.Action == CollectionChangeAction.Add || args.Action == CollectionChangeAction.Remove) || rel.Nested == false);
+ Debug.Assert(!(args.Action == CollectionChangeAction.Add || args.Action == CollectionChangeAction.Remove) || rel!.Nested == false);
if (args.Action == CollectionChangeAction.Refresh)
{
foreach (DataRelation relTemp in (DataRelationCollection)oRelationsCollection)
}
}
- private void OnRelationPropertyChanging(object oRelationsCollection, PropertyChangedEventArgs args)
+ private void OnRelationPropertyChanging(object? oRelationsCollection, PropertyChangedEventArgs args)
{
if (args.PropertyName == "Nested")
throw new InvalidOperationException(SR.DataDom_DataSetNestedRelationsChange);
private void OnUndeleteRow(DataRow row, XmlElement rowElement)
{
- XmlNode refRow;
+ XmlNode? refRow;
XmlElement parent;
// make certain we weren't place somewhere else.
rowElement.ParentNode.RemoveChild(rowElement);
// Find the parent of RowNode to be inserted
- DataRow parentRowInRelation = GetNestedParent(row);
+ DataRow? parentRowInRelation = GetNestedParent(row);
if (parentRowInRelation == null)
{
parent = EnsureNonRowDocumentElement();
Debug.Assert(parent != DocumentElement); // We cannot promote children of the DocumentElement
XmlNode prevSibling = parent;
- XmlBoundElement parentRegionRowElem;
+ XmlBoundElement? parentRegionRowElem;
_mapper.GetRegion(parent.ParentNode, out parentRegionRowElem);
TreeIterator iter = new TreeIterator(parent);
{
Debug.Assert(parent != null);
XmlNode prevSibling = parent;
- XmlNode child = parent.FirstChild;
+ XmlNode? child = parent.FirstChild;
bool bTextLikeNode = true;
- XmlNode nextSibling = null;
+ XmlNode? nextSibling = null;
while (child != null)
{
nextSibling = child.NextSibling;
}
}
- private void RemoveInitialTextNodes(XmlNode node)
+ private void RemoveInitialTextNodes(XmlNode? node)
{
while (node != null && IsTextLikeNode(node))
{
- XmlNode sibling = node.NextSibling;
- node.ParentNode.RemoveChild(node);
+ XmlNode? sibling = node.NextSibling;
+ node.ParentNode!.RemoveChild(node);
node = sibling;
}
}
private void ReplaceInitialChildText(XmlNode parent, string value)
{
- XmlNode n = parent.FirstChild;
+ XmlNode? n = parent.FirstChild;
// don't consider whitespace when replacing initial text
while (n != null && n.NodeType == XmlNodeType.Whitespace)
n.Value = value;
else
n = parent.InsertBefore(CreateTextNode(value), n);
- RemoveInitialTextNodes(n.NextSibling);
+ RemoveInitialTextNodes(n!.NextSibling);
}
else
{
}
}
- internal XmlNode SafeFirstChild(XmlNode n)
+ internal XmlNode? SafeFirstChild(XmlNode n)
{
- XmlBoundElement be = n as XmlBoundElement;
+ XmlBoundElement? be = n as XmlBoundElement;
if (be != null)
return be.SafeFirstChild;
else
return n.FirstChild;
}
- internal XmlNode SafeNextSibling(XmlNode n)
+ internal XmlNode? SafeNextSibling(XmlNode n)
{
- XmlBoundElement be = n as XmlBoundElement;
+ XmlBoundElement? be = n as XmlBoundElement;
if (be != null)
return be.SafeNextSibling;
else
return n.NextSibling;
}
- internal XmlNode SafePreviousSibling(XmlNode n)
+ internal XmlNode? SafePreviousSibling(XmlNode n)
{
- XmlBoundElement be = n as XmlBoundElement;
+ XmlBoundElement? be = n as XmlBoundElement;
if (be != null)
return be.SafePreviousSibling;
else
internal static void SetRowValueFromXmlText(DataRow row, DataColumn col, string xmlText)
{
Debug.Assert(xmlText != null);
- Debug.Assert(row.Table.DataSet.EnforceConstraints == false);
+ Debug.Assert(row.Table.DataSet!.EnforceConstraints == false);
object oVal;
try
{
}
// Sync row fields w/ values from rowElem region.
// If rowElemList is != null, all subregions of rowElem are appended to it.
- private void SynchronizeRowFromRowElement(XmlBoundElement rowElement, ArrayList rowElemList)
+ private void SynchronizeRowFromRowElement(XmlBoundElement rowElement, ArrayList? rowElemList)
{
- DataRow row = rowElement.Row;
+ DataRow? row = rowElement.Row;
Debug.Assert(row != null);
// No synchronization needed for deleted rows
}
#endif
}
- private void SynchronizeRowFromRowElementEx(XmlBoundElement rowElement, ArrayList rowElemList)
+ private void SynchronizeRowFromRowElementEx(XmlBoundElement rowElement, ArrayList? rowElemList)
{
Debug.Assert(rowElement != null);
Debug.Assert(rowElement.Row != null);
RegionIterator iter = new RegionIterator(rowElement);
bool fMore;
// If present, fill up the TextOnly column
- DataColumn column = GetTextOnlyColumn(row);
+ DataColumn? column = GetTextOnlyColumn(row);
if (column != null)
{
foundColumns[column] = column;
// Fill up the columns mapped to an element
while (fMore)
{
- XmlElement e = iter.CurrentNode as XmlElement;
+ XmlElement? e = iter.CurrentNode as XmlElement;
if (e == null)
{
fMore = iter.Next();
continue;
}
- XmlBoundElement be = e as XmlBoundElement;
+ XmlBoundElement? be = e as XmlBoundElement;
if (be != null && be.Row != null)
{
if (rowElemList != null)
continue;
}
- DataColumn c = _mapper.GetColumnSchemaForNode(rowElement, e);
+ DataColumn? c = _mapper.GetColumnSchemaForNode(rowElement, e);
if (c != null)
{
Debug.Assert(c.Table == row.Table);
//
foreach (XmlAttribute attr in rowElement.Attributes)
{
- DataColumn c = _mapper.GetColumnSchemaForNode(rowElement, attr);
+ DataColumn? c = _mapper.GetColumnSchemaForNode(rowElement, attr);
if (c != null)
{
internal XmlDataDocument(XmlImplementation imp) : base(imp)
{
- }
-
+ // This constructor is used by XmlDataImplementation.CreateDocument(), which
+ // exposes it as XmlDocument. The methods using these fields are never called.
+ _dataSet = null!;
+ _pointers = null!;
+ _columnChangeList = null!;
+ _mapper = null!;
+ _foliationLock = null!;
+ _attrXml = null!;
+ }
+
+ [MemberNotNull(nameof(_pointers))]
+ [MemberNotNull(nameof(_columnChangeList))]
+ [MemberNotNull(nameof(_mapper))]
+ [MemberNotNull(nameof(_foliationLock))]
+ [MemberNotNull(nameof(_attrXml))]
private void Init()
{
_pointers = new Hashtable();
_ignoreXmlEvents = false;
}
+ [MemberNotNull(nameof(_pointers))]
+ [MemberNotNull(nameof(_columnChangeList))]
+ [MemberNotNull(nameof(_mapper))]
+ [MemberNotNull(nameof(_foliationLock))]
+ [MemberNotNull(nameof(_attrXml))]
+ [MemberNotNull(nameof(_dataSet))]
private void Init(DataSet ds)
{
if (ds == null)
Bind(true);
}
- private bool IsConnected(XmlNode node)
+ private bool IsConnected(XmlNode? node)
{
while (true)
{
if (node == this)
return true;
- XmlAttribute attr = node as XmlAttribute;
+ XmlAttribute? attr = node as XmlAttribute;
if (attr != null)
node = attr.OwnerElement;
else
{
return (row.RowState & (DataRowState.Added | DataRowState.Unchanged | DataRowState.Modified)) != 0;
}
- private static void SetNestedParentRow(DataRow childRow, DataRow parentRow)
+ private static void SetNestedParentRow(DataRow childRow, DataRow? parentRow)
{
- DataRelation rel = GetNestedParentRelation(childRow);
+ DataRelation? rel = GetNestedParentRelation(childRow);
//we should not set this row's parentRow if the table doesn't match.
if (rel != null)
{
// A node (node) was inserted into the main tree (connected) from oldParent==null state
private void OnNodeInsertedInTree(XmlNode node)
{
- XmlBoundElement be;
+ XmlBoundElement? be;
ArrayList rowElemList = new ArrayList();
if (_mapper.GetRegion(node, out be))
{
while (rowElemList.Count > 0)
{
Debug.Assert(rowElemList[0] != null && rowElemList[0] is XmlBoundElement);
- XmlBoundElement subRowElem = (XmlBoundElement)(rowElemList[0]);
+ XmlBoundElement? subRowElem = (XmlBoundElement?)(rowElemList[0]);
rowElemList.RemoveAt(0);
// Expect rowElem to have a DataTable schema, since it is a sub-region
Debug.Assert(subRowElem != null);
// "node" was inserting into a disconnected tree from oldParent==null state
private void OnNodeInsertedInFragment(XmlNode node)
{
- XmlBoundElement be;
+ XmlBoundElement? be;
if (_mapper.GetRegion(node, out be))
{
if (be == node)
{
- Debug.Assert(!IsRowLive(be.Row));
+ Debug.Assert(!IsRowLive(be.Row!));
SetNestedParentRegion(be);
}
else
while (rowElemList.Count > 0)
{
Debug.Assert(rowElemList[0] != null && rowElemList[0] is XmlBoundElement);
- XmlBoundElement subRowElem = (XmlBoundElement)(rowElemList[0]);
+ XmlBoundElement subRowElem = (XmlBoundElement)(rowElemList[0]!);
rowElemList.RemoveAt(0);
SetNestedParentRegion(subRowElem, be);
}
#if DEBUG
try
{
- Debug.Assert(row.Table.DataSet.EnforceConstraints == false);
+ Debug.Assert(row.Table.DataSet!.EnforceConstraints == false);
#endif
row.Table.Rows.Add(row);
SetNestedParentRegion(rowElem);
#if DEBUG
try
{
- Debug.Assert(row.Table.DataSet.EnforceConstraints == false);
+ Debug.Assert(row.Table.DataSet!.EnforceConstraints == false);
#endif
// Change the row status to be alive (unchanged)
row.RejectChanges();
#if DEBUG
try
{
- Debug.Assert(row.Table.DataSet.EnforceConstraints == false);
+ Debug.Assert(row.Table.DataSet!.EnforceConstraints == false);
#endif
SetNestedParentRegion(rowElem);
#if DEBUG
private void OnNonRowElementInsertedInTree(XmlNode node, XmlBoundElement rowElement, ArrayList rowElemList)
{
// non-row-elem is beeing inserted
- DataRow row = rowElement.Row;
+ DataRow? row = rowElement.Row;
// Region should already have an associated data row (otherwise how was the original row-elem inserted ?)
Debug.Assert(row != null);
SynchronizeRowFromRowElement(rowElement);
private void OnNonRowElementInsertedInFragment(XmlNode node, XmlBoundElement rowElement, ArrayList rowElemList)
{
// non-row-elem is beeing inserted
- DataRow row = rowElement.Row;
+ DataRow? row = rowElement.Row;
// Region should already have an associated data row (otherwise how was the original row-elem inserted ?)
Debug.Assert(row != null);
// Since oldParent == null, the only 2 row states should have been Detached or Deleted
{
Debug.Assert(childRowElem.Row != null);
- XmlBoundElement parentRowElem;
+ XmlBoundElement? parentRowElem;
_mapper.GetRegion(childRowElem.ParentNode, out parentRowElem);
SetNestedParentRegion(childRowElem, parentRowElem);
}
- private void SetNestedParentRegion(XmlBoundElement childRowElem, XmlBoundElement parentRowElem)
+ private void SetNestedParentRegion(XmlBoundElement childRowElem, XmlBoundElement? parentRowElem)
{
- DataRow childRow = childRowElem.Row;
+ DataRow childRow = childRowElem.Row!;
if (parentRowElem == null)
{
SetNestedParentRow(childRow, null);
return;
}
+ Debug.Assert(parentRowElem.Row != null);
DataRow parentRow = parentRowElem.Row;
- Debug.Assert(parentRow != null);
// We should set it only if there is a nested relationship between this child and parent regions
DataRelation[] relations = childRow.Table.NestedParentRelations;
if (relations.Length != 0 && relations[0].ParentTable == parentRow.Table) // just backward compatable
}
*/
- protected override XPathNavigator CreateNavigator(XmlNode node)
+ protected override XPathNavigator? CreateNavigator(XmlNode node)
{
Debug.Assert(node.OwnerDocument == this || node == this);
if (XPathNodePointer.s_xmlNodeType_To_XpathNodeType_Map[(int)(node.NodeType)] == -1)
return null;
if (IsTextNode(node.NodeType))
{
- XmlNode parent = node.ParentNode;
+ XmlNode? parent = node.ParentNode;
if (parent != null && parent.NodeType == XmlNodeType.Attribute)
return null;
else
{
#if DEBUG
//if current node is a text node, its parent node has to be foliated
- XmlBoundElement be = node.ParentNode as XmlBoundElement;
+ XmlBoundElement? be = node.ParentNode as XmlBoundElement;
if (be != null)
Debug.Assert(be.IsFoliated);
#endif
- XmlNode prevSib = node.PreviousSibling;
+ XmlNode? prevSib = node.PreviousSibling;
while (prevSib != null && IsTextNode(prevSib.NodeType))
{
node = prevSib;
IsFoliationEnabled = false;
try
{
- XmlBoundElement rowElement = node as XmlBoundElement;
+ XmlBoundElement? rowElement = node as XmlBoundElement;
if (rowElement != null && rowElement.Row != null)
Debug.Assert(IsRowLive(rowElement.Row));
TreeIterator iter = new TreeIterator(node);
for (bool fMore = iter.NextRowElement(); fMore; fMore = iter.NextRowElement())
{
rowElement = iter.CurrentNode as XmlBoundElement;
- Debug.Assert(rowElement.Row != null);
+ Debug.Assert(rowElement!.Row != null);
Debug.Assert(IsRowLive(rowElement.Row));
}
}
IsFoliationEnabled = false;
try
{
- XmlBoundElement rowElement = node as XmlBoundElement;
+ XmlBoundElement? rowElement = node as XmlBoundElement;
if (rowElement != null && rowElement.Row != null)
Debug.Assert(!IsRowLive(rowElement.Row));
TreeIterator iter = new TreeIterator(node);
for (bool fMore = iter.NextRowElement(); fMore; fMore = iter.NextRowElement())
{
rowElement = iter.CurrentNode as XmlBoundElement;
- Debug.Assert(rowElement.Row != null);
+ Debug.Assert(rowElement!.Row != null);
Debug.Assert(!IsRowLive(rowElement.Row));
}
}
}
}
- public override XmlElement GetElementById(string elemId)
+ public override XmlElement? GetElementById(string elemId)
{
throw new NotSupportedException(SR.DataDom_NotSupport_GetElementById);
}
// after adding Namespace support foir datatable, DataSet does not guarantee that infered tabels would be in the same sequence as they rae in XML, because
// of Namespace. if a table is in different namespace than its children and DataSet, that table would efinetely be added to DataSet after its children. Its By Design
// so in order to maintain backward compatability, we reorder the copy of the datatable collection and use it
- private DataTable[] OrderTables(DataSet ds)
+ private DataTable[] OrderTables(DataSet? ds)
{
- DataTable[] retValue = null;
+ DataTable[]? retValue = null;
if (ds == null || ds.Tables.Count == 0)
{
retValue = Array.Empty<DataTable>();
if (null == retValue)
{
- retValue = new DataTable[ds.Tables.Count];
+ retValue = new DataTable[ds!.Tables.Count];
List<DataTable> tableList = new List<DataTable>();
// first take the root tables that have no parent
foreach (DataTable dt in ds.Tables)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO: Enable after System.Private.Xml is annotated
-#nullable disable
-
#pragma warning disable 618 // ignore obsolete warning about XmlDataDocument
namespace System.Xml