internal bool CanRemove(DataTable table, bool fThrowException)
{
IntPtr hscp;
Bid.ScopeEnter(out hscp, "<ds.DataTableCollection.CanRemove|INFO> %d#, table=%d, fThrowException=%d{bool}\n", ObjectID, (table != null)? table.ObjectID : 0, fThrowException);
try {
if (table == null)
{
if (!fThrowException)
{
return(false);
}
else
{
throw ExceptionBuilder.ArgumentNull("table");
}
}
if (table.DataSet != dataSet)
{
if (!fThrowException)
{
return(false);
}
else
{
throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
}
}
// allow subclasses to throw.
dataSet.OnRemoveTable(table);
if (table.ChildRelations.Count != 0 || table.ParentRelations.Count != 0)
{
if (!fThrowException)
{
return(false);
}
else
{
throw ExceptionBuilder.TableInRelation();
}
}
for (ParentForeignKeyConstraintEnumerator constraints = new ParentForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();)
{
ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
if (constraint.Table == table && constraint.RelatedTable == table) // we can go with (constraint.Table == constraint.RelatedTable)
{
continue;
}
if (!fThrowException)
{
return(false);
}
else
{
throw ExceptionBuilder.TableInConstraint(table, constraint);
}
}
for (ChildForeignKeyConstraintEnumerator constraints = new ChildForeignKeyConstraintEnumerator(dataSet, table); constraints.GetNext();)
{
ForeignKeyConstraint constraint = constraints.GetForeignKeyConstraint();
if (constraint.Table == table && constraint.RelatedTable == table) // bug 97670
{
continue;
}
if (!fThrowException)
{
return(false);
}
else
{
throw ExceptionBuilder.TableInConstraint(table, constraint);
}
}
return(true);
}
finally{
Bid.ScopeLeave(ref hscp);
}
}