With this sort of code:
public void UpdateCellFont(int id, string colName, Font font)
{
CellLocation location = new CellLocation(id, colName);
if (CellAppearances.ContainsKey(location))
{
CellAppearances[location].Font = font;
}
else
{
CellAppearance cell = new CellAppearance(font, _DefaultBackColor, _DefaultForeColor);
CellAppearances.Add(location, cell);
}
}
public void UpdateCellBackColor(int id, string colName, Color backColor)
{
CellLocation location = new CellLocation(id, colName);
if (CellAppearances.ContainsKey(location))
{
CellAppearances[location].BackColor = backColor;
}
else
{
CellAppearance cell = new CellAppearance(_DefaultFont, backColor, _DefaultForeColor);
CellAppearances.Add(location, cell);
}
}
public void UpdateCellForeColor(int id, string colName, Color foreColor)
{
CellLocation location = new CellLocation(id, colName);
if (CellAppearances.ContainsKey(location))
{
CellAppearances[location].ForeColor = foreColor;
}
else
{
CellAppearance cell = new CellAppearance(_DefaultFont, _DefaultBackColor, foreColor);
CellAppearances.Add(location, cell);
}
}
The methods all do almost the same thing – each one updates Font, BackColor or ForeColor (or if there is no entry in the dictionary they create a new one.
How can I reduce the duplication here when they are acting on a strongly typed CellAppearance?
Thanks
what about that straight-forward?