DataKey.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Data / System / Data / DataKey.cs / 1 / DataKey.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
// [....]
// [....] 
//----------------------------------------------------------------------------- 

namespace System.Data { 
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
 
    internal struct DataKey {
        internal const Int32 COLUMN     = unchecked((int)0x0000FFFF); 
        internal const Int32 DESCENDING = unchecked((int)0x80000000); 
        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(); 
                }
            }
        }
 
        internal bool ColumnsEqual(DataKey key) {
            //check to see if this.columns && key2's columns are equal regardless of order 
            DataColumn[] column1=columns; 
            DataColumn[] column2=((DataKey)key).columns;
 
            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
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
// [....]
// [....] 
//----------------------------------------------------------------------------- 

namespace System.Data { 
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
 
    internal struct DataKey {
        internal const Int32 COLUMN     = unchecked((int)0x0000FFFF); 
        internal const Int32 DESCENDING = unchecked((int)0x80000000); 
        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(); 
                }
            }
        }
 
        internal bool ColumnsEqual(DataKey key) {
            //check to see if this.columns && key2's columns are equal regardless of order 
            DataColumn[] column1=columns; 
            DataColumn[] column2=((DataKey)key).columns;
 
            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

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK