我用下面的代码在某些方面实现INotifyPropertyChanged
:LocationInterceptionAspect.OnSetValue(LocationInterceptionArgs args):如何检查属性是否为索引器并获取其值?
[Serializable]
public class NotifyPropertyChangedAspect : LocationInterceptionAspect {
/* ... stuff ... */
public override void OnSetValue(LocationInterceptionArgs args)
{
var obj = args.Instance;
/* ... more stuff ... */
var oldValue = args.Binding.GetValue(ref obj, Arguments.Empty);
/* ... extra stuff ... */
}
}
但如果我的属性是一个索引,那么它失败的异常InvalidCastException
:
Unable to cast object of type 'PostSharp.Aspects.Internals.Arguments`1[PostSharp.Aspects.Arguments]' to type 'PostSharp.Aspects.Internals.Arguments`1[System.Int32]'.
如何检查如果该属性是一个索引器,并获得它的值(我宁愿在编译过程中进行检查,我猜在CompileTimeInitialize
方法中)?