public DataSet GetChanges(DataRowState rowStates)
{
long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.GetChanges|API> {0}, rowStates={1}", ObjectID, rowStates);
try
{
DataSet dsNew = null;
bool fEnforceConstraints = false;
if (0 != (rowStates & ~(DataRowState.Added | DataRowState.Deleted | DataRowState.Modified | DataRowState.Unchanged)))
{
throw ExceptionBuilder.InvalidRowState(rowStates);
}
// Initialize all the individual table bitmaps.
TableChanges[] bitMatrix = new TableChanges[Tables.Count];
for (int i = 0; i < bitMatrix.Length; ++i)
{
bitMatrix[i] = new TableChanges(Tables[i].Rows.Count);
}
// find all the modified rows and their parents
MarkModifiedRows(bitMatrix, rowStates);
// copy the changes to a cloned table
for (int i = 0; i < bitMatrix.Length; ++i)
{
Debug.Assert(0 <= bitMatrix[i].HasChanges, "negative change count");
if (0 < bitMatrix[i].HasChanges)
{
if (null == dsNew)
{
dsNew = Clone();
fEnforceConstraints = dsNew.EnforceConstraints;
dsNew.EnforceConstraints = false;
}
DataTable table = Tables[i];
DataTable destTable = dsNew.Tables[table.TableName, table.Namespace];
Debug.Assert(bitMatrix[i].HasChanges <= table.Rows.Count, "to many changes");
for (int j = 0; 0 < bitMatrix[i].HasChanges; ++j)
{
// Loop through the rows.
if (bitMatrix[i][j])
{
table.CopyRow(destTable, table.Rows[j]);
bitMatrix[i].HasChanges--;
}
}
}
}
if (null != dsNew)
{
dsNew.EnforceConstraints = fEnforceConstraints;
}
return dsNew;
}
finally
{
DataCommonEventSource.Log.ExitScope(logScopeId);
}
}