How can I implement an interface member in protected ?

Posted by Nicolas Dorier on Stack Overflow See other posts from Stack Overflow or by Nicolas Dorier
Published on 2010-03-19T09:58:09Z Indexed on 2010/03/19 10:01 UTC
Read the original article Hit count: 240

Filed under:
|

Hi,

I've been quite surprise when I saw the metadata of ReadOnlyObservableCollection in VS 2008...

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);
}

As you can see, CollectionChanged, a member of INotifyCollectionChanged is implemented in protected... and I can't do that in my own class.

.NET framework should not compile !

Does someone has an explanation of this mystery ?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#