【发布时间】:2010-03-19 09:58:09
【问题描述】:
当我在 VS 2008 中看到 ReadOnlyObservableCollection 的元数据时,我感到非常惊讶......
public class ReadOnlyObservableCollection<T> : ReadOnlyCollection<T>, INotifyCollectionChanged, INotifyPropertyChanged
{
// Summary:
// Initializes a new instance of the System.Collections.ObjectModel.ReadOnlyObservableCollection<T>
// class that serves as a wrapper for the specified System.Collections.ObjectModel.ObservableCollection<T>.
//
// Parameters:
// list:
// The collection to wrap.
public ReadOnlyObservableCollection(ObservableCollection<T> list);
// Summary:
// Occurs when an item is added or removed.
protected virtual event NotifyCollectionChangedEventHandler CollectionChanged;
//
// Summary:
// Occurs when a property value changes.
protected virtual event PropertyChangedEventHandler PropertyChanged;
// Summary:
// Raises the System.Collections.ObjectModel.ReadOnlyObservableCollection<T>.CollectionChanged
// event.
//
// Parameters:
// args:
// The event data.
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs args);
//
// Summary:
// Raises the System.Collections.ObjectModel.ReadOnlyObservableCollection<T>.PropertyChanged
// event.
//
// Parameters:
// args:
// The event data.
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args);
}
如您所见,INotifyCollectionChanged 的成员 CollectionChanged 是在 protected... 中实现的,而我无法在自己的类中这样做。
.NET 框架不应该编译!
有人解释过这个谜吗?
【问题讨论】: