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
});
}
}
Comme vous pouvez le voir, je suis le suivi des modifications sur ce message entrant, pour exécuter les modifications sur un autre objet. La méthode à exécuter est transmise à PropertyChanged en tant que chaîne. Est-ce que quelqu'un a une astuce comment je peux faire ce type de coffre-fort?Effectuez cette méthode de réflexion callafe safe
Oui! Merci beaucoup :) – moe