この種のコードでは:
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);
}
}
メソッドはすべてほぼ同じことを行います。それぞれが Font、BackColor、または ForeColor を更新します (辞書にエントリがない場合は、新しいエントリを作成します)。
強く型付けされた CellAppearance で動作している場合、ここで重複を減らすにはどうすればよいですか?
ありがとう