//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // // Microsoft // Microsoft // Microsoft //------------------------------------------------------------------------------ namespace System.Data { using System; using System.Diagnostics; using System.ComponentModel; internal struct DataKey { private const int maxColumns = 32; private readonly DataColumn[] columns; /// /// [To be supplied.] /// internal DataKey(DataColumn[] columns, bool copyColumns) { if (columns == null) throw ExceptionBuilder.ArgumentNull("columns"); if (columns.Length == 0) throw ExceptionBuilder.KeyNoColumns(); if (columns.Length > maxColumns) throw ExceptionBuilder.KeyTooManyColumns(maxColumns); for (int i = 0; i < columns.Length; i++) { if (columns[i] == null) throw ExceptionBuilder.ArgumentNull("column"); } for (int i = 0; i < columns.Length; i++) { for (int j = 0; j < i; j++) { if (columns[i] == columns[j]) { throw ExceptionBuilder.KeyDuplicateColumns(columns[i].ColumnName); } } } if (copyColumns) { // Need to make a copy of all columns this.columns = new DataColumn [columns.Length]; for (int i = 0; i < columns.Length; i++) this.columns[i] = columns[i]; } else { // take ownership of the array passed in this.columns = columns; } CheckState(); } internal DataColumn[] ColumnsReference { get { return columns; } } internal bool HasValue { get { return (null != columns); } } internal DataTable Table { get { return columns[0].Table; } } internal void CheckState() { DataTable table = columns[0].Table; if (table == null) { throw ExceptionBuilder.ColumnNotInAnyTable(); } for (int i = 1; i < columns.Length; i++) { if (columns[i].Table == null) { throw ExceptionBuilder.ColumnNotInAnyTable(); } if (columns[i].Table != table) { throw ExceptionBuilder.KeyTableMismatch(); } } } //check to see if this.columns && key2's columns are equal regardless of order internal bool ColumnsEqual(DataKey key) { return ColumnsEqual(this.columns, ((DataKey)key).columns); } //check to see if columns1 && columns2 are equal regardless of order internal static bool ColumnsEqual(DataColumn[] column1, DataColumn[] column2) { if (column1 == column2) { return true; } else if (column1 == null || column2 == null) { return false; } else if (column1.Length != column2.Length) { return false; } else { int i, j; for (i=0; i