private void RenameColsViewInternal(Matrix <TRowKey, TColKey, TValue> parentMatrix, IEnumerable <KeyValuePair <TColKey, TColKey> > newNameAndOldNameSequence) { NewKeyToOldKey = newNameAndOldNameSequence.ToDictionary(pair => pair.Key, pair => pair.Value).AsRestrictedAccessDictionary(); var unmatchedCols = NewKeyToOldKey.Values.Except(parentMatrix.ColKeys).ToList(); Helper.CheckCondition(unmatchedCols.Count == 0, Properties.Resource.ExpectedEveryRemappedColKeyToBeInOriginalMatrix, unmatchedCols.StringJoin(",")); ParentMatrix = parentMatrix; _colKeys = NewKeyToOldKey.Select(pair => pair.Key).ToList().AsReadOnly(); _indexOfColKey = _colKeys.Select((key, idx) => new KeyValuePair <TColKey, int>(key, idx)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value).AsRestrictedAccessDictionary(); NewIndexToOldIndex = ( from newIndex in Enumerable.Range(0, ColCount) let newKey = ColKeys[newIndex] let oldKey = NewKeyToOldKey[newKey] let oldIndex = parentMatrix.IndexOfColKey[oldKey] select oldIndex ).ToList().AsReadOnly(); }