using System; using System.Collections.Generic; using System.Text; namespace sharpcomparer { public class Column : IComparable { private string tableCatalog; private string tableSchema; private string tableName; private string columnName; private int ordinalPosition; private string columnDefault; private bool isNullable; private string dataType; private int characterMaximumLength; private int characterOctetLength; private byte numericPrecision; private short numericPrecisionRadix; private int numericScale; private short datetimePrecision; private string characterSetCatalog; private string characterSetSchema; private string characterSetName; private string collationCatalog; public string TableCatalog { get { return tableCatalog; } set { tableCatalog = value; } } public string TableSchema { get { return tableSchema; } set { tableSchema = value; } } public string TableName { get { return tableName; } set { tableName = value; } } public string ColumnName { get { return columnName; } set { columnName = value; } } public int OrdinalPosition { get { return ordinalPosition; } set { ordinalPosition = value; } } public string ColumnDefault { get { return columnDefault; } set { columnDefault = value; } } public bool IsNullable { get { return isNullable; } set { isNullable = value; } } public string DataType { get { return dataType; } set { dataType = value; } } public int CharacterMaximumLength { get { return characterMaximumLength; } set { characterMaximumLength = value; } } public int CharacterOctetLength { get { return characterOctetLength; } set { characterOctetLength = value; } } public byte NumericPrecision { get { return numericPrecision; } set { numericPrecision = value; } } public short NumericPrecisionRadix { get { return numericPrecisionRadix; } set { numericPrecisionRadix = value; } } public int NumericScale { get { return numericScale; } set { numericScale = value; } } public short DatetimePrecision { get { return datetimePrecision; } set { datetimePrecision = value; } } public string CharacterSetCatalog { get { return characterSetCatalog; } set { characterSetCatalog = value; } } public string CharacterSetSchema { get { return characterSetSchema; } set { characterSetSchema = value; } } public string CharacterSetName { get { return characterSetName; } set { characterSetName = value; } } public string CollationCatalog { get { return collationCatalog; } set { collationCatalog = value; } } public string Type { get { return CharacterMaximumLength != -1 ? string.Format("{0}({1})", DataType, CharacterMaximumLength) : DataType; } } public Column( string tableCatalog, string tableSchema, string tableName, string columnName, int ordinalPosition, string columnDefault, bool isNullable, string dataType, int characterMaximumLength, int characterOctetLength, byte numericPrecision, short numericPrecisionRadix, int numericScale, short datetimePrecision, string characterSetCatalog, string characterSetSchema, string characterSetName, string collationCatalog) { this.tableCatalog = tableCatalog; this.tableSchema = tableSchema; this.tableName = tableName; this.columnName = columnName; this.ordinalPosition = ordinalPosition; this.columnDefault = columnDefault; this.isNullable = isNullable; this.dataType = dataType; this.characterMaximumLength = characterMaximumLength; this.characterOctetLength = characterOctetLength; this.numericPrecision = numericPrecision; this.numericPrecisionRadix = numericPrecisionRadix; this.numericScale = numericScale; this.datetimePrecision = datetimePrecision; this.characterSetCatalog = characterSetCatalog; this.characterSetSchema = characterSetSchema; this.characterSetName = characterSetName; this.collationCatalog = collationCatalog; } public static bool operator ==(Column a, Column b) { if (System.Object.ReferenceEquals(a, b)) { return true; } if (((object)a == null) || ((object)b == null)) { return false; } return a.tableCatalog == b.tableCatalog && a.tableSchema == b.TableSchema && a.tableName == b.TableName && a.columnName == b.ColumnName && a.ordinalPosition == b.OrdinalPosition && a.columnDefault == b.ColumnDefault && a.isNullable == b.isNullable && a.dataType == b.dataType && a.characterMaximumLength == b.characterMaximumLength && a.characterOctetLength == b.characterOctetLength && a.numericPrecision == b.numericPrecision && a.numericPrecisionRadix == b.numericPrecisionRadix && a.numericScale == b.numericScale && a.datetimePrecision == b.datetimePrecision && a.characterSetCatalog == b.characterSetCatalog && a.characterSetSchema == b.characterSetSchema && a.characterSetName == b.characterSetName && a.collationCatalog == b.collationCatalog; } public static bool operator !=(Column a, Column b) { return !(a == b); } public override int GetHashCode() { return base.GetHashCode(); } #region IComparable Members public int CompareTo(Column other) { int comparison = columnName.CompareTo(other.ColumnName); if (comparison == 0) { comparison = isNullable.CompareTo(other.isNullable); } if (comparison == 0) { comparison = Type.CompareTo(other.Type); } return comparison; } #endregion } }