class CustomerMessage
{
private string name;
private Dictionary<MethodBase, object> changeTrackingMethods =
new Dictionary<MethodBase, object>();
public int Id { get; set; }
public string Name {
get { return this.name; }
set
{
this.name = value;
this.PropertyChanged("SetName", value);
}
}
private void PropertyChanged(string behaviorMethod, object value)
{
var method = typeof(Customer).GetMethod(behaviorMethod);
this.changeTrackingMethods.Add(method, value);
}
public void ApplyChanges(Customer c)
{
foreach (var changedProperty in this.changeTrackingMethods)
changedProperty.Key.Invoke(c, new object[] {
changedProperty.Value
});
}
}
正如您所看到的,我正在跟蹤此傳入消息的更改,以在另一個對象上運行更改。要運行的方法以字符串形式傳遞給PropertyChanged。有沒有人有提示我如何使這種類型安全?使此反射方法調用類型安全
是的!非常感謝:) – moe 2010-06-28 16:27:01