/// <summary> /// Rename a collection /// </summary> public bool RenameCollection(string collection, string newName) { if (collection.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(collection)); } if (newName.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(newName)); } return(Transaction <bool>(collection, false, (col) => { if (col == null) { return false; } _log.Write(Logger.Command, "rename collection '{0}' -> '{1}'", collection, newName); // check if newName already exists if (GetCollectionNames().Contains(newName, StringComparer.OrdinalIgnoreCase)) { throw LiteException.AlreadyExistsCollectionName(newName); } // change collection name and save col.CollectionName = newName; // set collection page as dirty _pager.SetDirty(col); // update header collection reference var header = _pager.GetPage <HeaderPage>(0); header.CollectionPages.Remove(collection); header.CollectionPages.Add(newName, col.PageID); _pager.SetDirty(header); return true; })); }