我用下面的代碼在某些方面實現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
方法中)?