想象一下我有这门课:
Class Foo
{
public Bar b1 { get; set; }
public Bar b2 { get; set; }
public Bar b3 { get; set; }
public void UpdateBarsMyProp(bool value)
{
// ????
}
}
Class Bar
{
public bool MyProp { get; set; }
public bool UpdateMyProp(bool value)
{
this.MyProp = value;
}
}
更新 b1、b2 和 b3 中的属性 MyProp 的最佳方法是什么?
泛型?
代表?
编辑:
只是为了添加有关我的具体情况的更多信息:
我正在创建一个虚拟键盘,我正在使用 WPF MVVM,所以我有:
一个包含多个 Key ViewModel 的 KeyBoard ViewModel,我无法将它们存储在 List 中,因为我的 View(xaml 文件)需要将每个关键信息绑定到特定的 ViewModel。
现在,当用户按下虚拟 shift 按钮时,我需要我的 Keyboard ViewModel 对象来更新每个 Key ViewModel 中的显示字符。