internal void RegisterColumnName(string name, DataColumn column, DataTable table) { object obj2 = this.columnFromName[name]; if (obj2 != null) { if (!(obj2 is DataColumn)) { throw ExceptionBuilder.CannotAddDuplicate2(name); } if (column != null) { throw ExceptionBuilder.CannotAddDuplicate(name); } throw ExceptionBuilder.CannotAddDuplicate3(name); } if ((table != null) && (base.NamesEqual(name, this.MakeName(this.defaultNameIndex), true, this.table.Locale) != 0)) { do { this.defaultNameIndex++; }while (this.Contains(this.MakeName(this.defaultNameIndex))); } if (column != null) { column._hashCode = this.table.GetSpecialHashCode(name); this.columnFromName.Add(name, column); } else { this.columnFromName.Add(name, table); } }
/// <summary> /// Registers this name as being used in the collection. Will throw an ArgumentException /// if the name is already being used. Called by Add, All property, and Column.ColumnName property. /// if the name is equivalent to the next default name to hand out, we increment our defaultNameIndex. /// NOTE: To add a child table, pass column as null /// </summary> internal void RegisterColumnName(string name, DataColumn?column) { Debug.Assert(name != null); try { _columnFromName.Add(name, column); if (null != column) { column._hashCode = _table.GetSpecialHashCode(name); } } catch (ArgumentException) { // Argument exception means that there is already an existing key if (_columnFromName[name] != null) { if (column != null) { throw ExceptionBuilder.CannotAddDuplicate(name); } else { throw ExceptionBuilder.CannotAddDuplicate3(name); } } throw ExceptionBuilder.CannotAddDuplicate2(name); } // If we're adding a child table, then update defaultNameIndex to avoid colisions between the child table and auto-generated column names if ((column == null) && NamesEqual(name, MakeName(_defaultNameIndex), true, _table.Locale) != 0) { do { _defaultNameIndex++; } while (Contains(MakeName(_defaultNameIndex))); } }
/// <include file='doc\DataColumnCollection.uex' path='docs/doc[@for="DataColumnCollection.RegisterName"]/*' /> /// <devdoc> /// Registers this name as being used in the collection. Will throw an ArgumentException /// if the name is already being used. Called by Add, All property, and Column.ColumnName property. /// if the name is equivalent to the next default name to hand out, we increment our defaultNameIndex. /// </devdoc> internal void RegisterName(string name, Object obj) { Debug.Assert(name != null); Debug.Assert(obj is DataTable || obj is DataColumn); Object _exObject = columnFromName[name]; DataColumn _column = _exObject as DataColumn; if (_column != null) { if (obj is DataColumn) { throw ExceptionBuilder.CannotAddDuplicate(name); } else { throw ExceptionBuilder.CannotAddDuplicate2(name); } } if (_exObject != null) { throw ExceptionBuilder.CannotAddDuplicate3(name); } //we need to check wether the tableName is the same of the //next generable columnName and update defaultNameIndex accordingly if (obj is DataTable && NamesEqual(name, MakeName(defaultNameIndex), true, table.Locale) != 0) { do { defaultNameIndex++; } while (!Contains(MakeName(defaultNameIndex))); } columnFromName.Add(name, obj); }