【发布时间】:2017-05-12 17:49:24
【问题描述】:
这里是 PostSharp support discussion(标题:“NotifyPropertyChanged 和 ObservableCollection”),它引发了我对这个主题的最初困惑。进一步的解释在我发布的答案中(我的答案不是 100% 有信心)。
我有点困惑 PostSharp 的 [NotifyPropertyChanged] 方面如何影响类的集合属性(如果有的话),以及我是否需要使用 ObservableCollection<> 或 AdvisableCollection<>。如果我理解正确,如果我想要来自集合的通知,我必须至少将其更改为 ObservableCollection<>,对吗? [NotifyPropertyChanged] 方面不会神奇地使类中的任何集合类型都可观察。
如果是这样,那我什么时候使用ObservableCollection<> 或AdvisableCollection<>?当我需要 PostSharp 应用的聚合模式时,是否应该保留 AdvisableCollection<>?还是应该在应用 PostSharp 的 [NotifyPropertyChanged] 属性时始终使用 AdvisableCollection<> ?
[NotifyPropertyChanged]
public class Test {
public int PropVal { get; set; }
public List<string> PropCollection { get; set; } //Should this be ObservableCollection
//or AdvisableCollection?
}
【问题讨论】:
标签: c# containers observablecollection inotifypropertychanged postsharp