System.Data.DataColumnCollection.RegisterColumnName C# (CSharp) Method

RegisterColumnName() private method

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
private RegisterColumnName ( string name, DataColumn column ) : void
name string
column DataColumn
return void
        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)));
            }
        }