public ColumnStyle this[DataColumn key] { get { // first look at the column styles hash table, column itself is the key if (_columnStyles.TryGetValue(key, out var colstyle)) { return(colstyle); } if (_defaultColumnStyles.TryGetValue(key.GetType(), out colstyle)) { return(colstyle); } // second look to the defaultcolumnstyles hash table, key is the type of the column style System.Type searchstyletype = key.GetColumnStyleType(); if (null == searchstyletype) { throw new ApplicationException("Error: Column of type +" + key.GetType() + " returns no associated ColumnStyleType, you have to overload the method GetColumnStyleType."); } else { // if not successfull yet, we will create a new defaultColumnStyle colstyle = (ColumnStyle)Activator.CreateInstance(searchstyletype); colstyle.ParentObject = this; _defaultColumnStyles.Add(key.GetType(), colstyle); return(colstyle); } } set { bool hadOldValue = _columnStyles.TryGetValue(key, out var oldStyle); _columnStyles[key] = value ?? throw new ArgumentNullException("value"); value.ParentObject = this; if (hadOldValue) { oldStyle?.Dispose(); } else { AttachKey(key); } } }