我的方面:
[Serializable]
[MulticastAttributeUsage(MulticastTargets.Class, Inheritance = MulticastInheritance.Strict)]
public sealed class NotifyPropertyChangedAttribute : InstanceLevelAspect
{
[OnLocationSetValueAdvice, MulticastPointcut(Targets = MulticastTargets.Property)]
public void OnPropertySet(LocationInterceptionArgs args)
{
if (args.Value == args.GetCurrentValue()) return;
args.ProceedSetValue();
IPersistent iENtity = this.Instance as IPersistent;
if (iENtity != null)
{
// do something with iENtity
// need to identify property name without using reflection
}
}
}
我已将此 NotifyPropertyChangedAttribute 应用于整个类,因此我可以处理属性更改,一切都按预期工作。
但我想知道被更改的属性的名称(所以我可以将脏属性的名称存储在某个集合中)。我想使用 LocationInterceptionArgs::Location 但我读到了这个:
"Using this property causes the aspect weaver to generate code that has non-trivial runtime overhead."
有没有其他方法可以在我的方面获取受影响属性的名称,但不使用反射或其他运行时开销很大的代码?
任何想法(或更好的例子)?也许我可以以其他方式实现它?我只需要一些方法在运行时识别属性,即使没有名称 - 只是一些值,我可以使用它稍后在某些 Dictionary<> 中找到属性......
谢谢。