System.Data.DataColumnCollection.CanRemove C# (CSharp) Метод

CanRemove() приватный Метод

private CanRemove ( DataColumn column, bool fThrowException ) : bool
column DataColumn
fThrowException bool
Результат bool
        internal bool CanRemove(DataColumn column, bool fThrowException)
        {
            if (column == null)
            {
                if (!fThrowException)
                {
                    return false;
                }
                else
                {
                    throw ExceptionBuilder.ArgumentNull(nameof(column));
                }
            }

            if (column._table != _table)
            {
                if (!fThrowException)
                {
                    return false;
                }
                else
                {
                    throw ExceptionBuilder.CannotRemoveColumn();
                }
            }

            // allow subclasses to complain first.
            _table.OnRemoveColumnInternal(column);

            // We need to make sure the column is not involved in any Relations or Constriants
            if (_table._primaryKey != null && _table._primaryKey.Key.ContainsColumn(column))
            {
                if (!fThrowException)
                {
                    return false;
                }
                else
                {
                    throw ExceptionBuilder.CannotRemovePrimaryKey();
                }
            }

            for (int i = 0; i < _table.ParentRelations.Count; i++)
            {
                if (_table.ParentRelations[i].ChildKey.ContainsColumn(column))
                {
                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.CannotRemoveChildKey(_table.ParentRelations[i].RelationName);
                }
            }

            for (int i = 0; i < _table.ChildRelations.Count; i++)
            {
                if (_table.ChildRelations[i].ParentKey.ContainsColumn(column))
                {
                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.CannotRemoveChildKey(_table.ChildRelations[i].RelationName);
                }
            }

            for (int i = 0; i < _table.Constraints.Count; i++)
            {
                if (_table.Constraints[i].ContainsColumn(column))
                    if (!fThrowException)
                        return false;
                    else
                        throw ExceptionBuilder.CannotRemoveConstraint(_table.Constraints[i].ConstraintName, _table.Constraints[i].Table.TableName);
            }

            if (_table.DataSet != null)
            {
                for (ParentForeignKeyConstraintEnumerator en = new ParentForeignKeyConstraintEnumerator(_table.DataSet, _table); en.GetNext();)
                {
                    Constraint constraint = en.GetConstraint();
                    if (((ForeignKeyConstraint)constraint).ParentKey.ContainsColumn(column))
                        if (!fThrowException)
                            return false;
                        else
                            throw ExceptionBuilder.CannotRemoveConstraint(constraint.ConstraintName, constraint.Table.TableName);
                }
            }

            if (column._dependentColumns != null)
            {
                for (int i = 0; i < column._dependentColumns.Count; i++)
                {
                    DataColumn col = column._dependentColumns[i];
                    if (_fInClear && (col.Table == _table || col.Table == null))
                    {
                        continue;
                    }

                    if (col.Table == null)
                    {
                        continue;
                    }

                    Debug.Assert(col.Computed, "invalid (non an expression) column in the expression dependent columns");
                    DataExpression expr = col.DataExpression;
                    if ((expr != null) && (expr.DependsOn(column)))
                    {
                        if (!fThrowException)
                            return false;
                        else
                            throw ExceptionBuilder.CannotRemoveExpression(col.ColumnName, col.Expression);
                    }
                }
            }

            // you can't remove a column participating in an index,
            // while index events are suspended else the indexes won't be properly maintained.
            // However, all the above checks should catch those participating columns.
            // except when a column is in a DataView RowFilter or Sort clause
            foreach (Index index in _table.LiveIndexes) { }

            return true;
        }

Same methods

DataColumnCollection::CanRemove ( DataColumn column ) : bool