/// <summary> /// If text is null, throws an ArgumentNullException. /// /// Otherwise, if name is null or invalid, throws an InvalidNameException. /// /// Otherwise, the contents of the named cell becomes text. The method returns a /// list consisting of name plus the names of all other cells whose value depends, /// directly or indirectly, on the named cell. /// /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the /// list {A1, B1, C1} is returned. /// </summary> protected override IList <string> SetCellContents(string name, string text) { //Normalizes the name String normalizedName = name; //Creates a new Cell, with the name and text being passed Cell c = new Cell(normalizedName, text); //Sets the contents and value of the cell c.SetContents(text); c.SetValue(Lookup); //If the dictionary contains the key name, then it goes here if (dictionary.ContainsKey(normalizedName)) { //Sets the value associated with the name in the dictionary with the new Cell dictionary[normalizedName] = c; //If the contents of the cell is empty, then it removes it from the dictionary if ((string)c.GetContents() == "") { dictionary.Remove(normalizedName); } //Replaces the dependees of the name graph.ReplaceDependees(normalizedName, new HashSet <string>()); } else { //If the contents of the cell is not null, then it adds the cell to the dictionary if ((string)c.GetContents() != "") { dictionary.Add(normalizedName, c); } //Replaces the dependees of the name graph.ReplaceDependees(normalizedName, new HashSet <string>()); } //Gets the orders of the cell recalculated and stores it into a list List <string> recalculatedList = new List <string>(GetCellsToRecalculate(normalizedName)); //Recalculates the values of all the cells RecalculateValues(recalculatedList); //Sets changed to true Changed = true; //Returns the list of cells recalculated return(recalculatedList); }
public override object GetCellContents(string name) { // Normalize our cell name string cellName = Normalize(name); // Check for name CheckCellName(cellName); // Cell doesn't Exist if (!Cells.ContainsKey(cellName)) { return(""); } Cell temp = Cells[cellName]; return(temp.GetContents()); }