System.Xml.RegionIterator.NextRight C# (CSharp) Méthode

NextRight() private méthode

private NextRight ( ) : bool
Résultat bool
        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;
                return false;
            }

            ElementState oldState = _rowElement.ElementState;

            // 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;

            if (nextNode != null)
            {
                _currentNode = nextNode;
                // 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;
                return true;
            }

            // No next sibling, try the first sibling of from the parent chain
            nextNode = _currentNode;
            while (nextNode != _rowElement && nextNode.NextSibling == null)
            {
                nextNode = nextNode.ParentNode;
            }

            if (nextNode == _rowElement)
            {
                _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;
                return false;
            }

            _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;
            return true;
        }

Usage Example

Exemple #1
0
        private void SynchronizeRowFromRowElementEx(XmlBoundElement rowElement, ArrayList rowElemList)
        {
            Debug.Assert(rowElement != null);
            Debug.Assert(rowElement.Row != null);
            Debug.Assert(DataSet.EnforceConstraints == false);

            DataRow row = rowElement.Row;
            Debug.Assert(row != null);
            DataTable table = row.Table;

            Hashtable foundColumns = new Hashtable();
            string xsi_attrVal = string.Empty;

            RegionIterator iter = new RegionIterator(rowElement);
            bool fMore;
            // If present, fill up the TextOnly column
            DataColumn column = GetTextOnlyColumn(row);
            if (column != null)
            {
                foundColumns[column] = column;
                string value;
                fMore = iter.NextInitialTextLikeNodes(out value);
                if (value.Length == 0 && (((xsi_attrVal = rowElement.GetAttribute(XSI_NIL)) == "1") || xsi_attrVal == "true"))
                    row[column] = DBNull.Value;
                else
                    SetRowValueFromXmlText(row, column, value);
            }
            else
                fMore = iter.Next();

            // Fill up the columns mapped to an element
            while (fMore)
            {
                XmlElement e = iter.CurrentNode as XmlElement;
                if (e == null)
                {
                    fMore = iter.Next();
                    continue;
                }

                XmlBoundElement be = e as XmlBoundElement;
                if (be != null && be.Row != null)
                {
                    if (rowElemList != null)
                        rowElemList.Add(e);
                    // Skip over sub-regions
                    fMore = iter.NextRight();
                    continue;
                }

                DataColumn c = _mapper.GetColumnSchemaForNode(rowElement, e);
                if (c != null)
                {
                    Debug.Assert(c.Table == row.Table);
                    if (foundColumns[c] == null)
                    {
                        foundColumns[c] = c;
                        string value;
                        fMore = iter.NextInitialTextLikeNodes(out value);
                        if (value.Length == 0 && (((xsi_attrVal = e.GetAttribute(XSI_NIL)) == "1") || xsi_attrVal == "true"))
                            row[c] = DBNull.Value;
                        else
                            SetRowValueFromXmlText(row, c, value);
                        continue;
                    }
                }

                fMore = iter.Next();
            }

            //
            // Walk the attributes to find attributes that map to columns.
            //
            foreach (XmlAttribute attr in rowElement.Attributes)
            {
                DataColumn c = _mapper.GetColumnSchemaForNode(rowElement, attr);

                if (c != null)
                {
                    if (foundColumns[c] == null)
                    {
                        foundColumns[c] = c;
                        SetRowValueFromXmlText(row, c, attr.Value);
                    }
                }
            }

            // Null all columns values that aren't represented in the tree
            foreach (DataColumn c in row.Table.Columns)
            {
                if (foundColumns[c] == null && !IsNotMapped(c))
                {
                    if (!c.AutoIncrement)
                        SetRowValueToNull(row, c);
                    else
                        c.Init(row._tempRecord);
                }
            }
        }
All Usage Examples Of System.Xml.RegionIterator::NextRight