event hiding in inherited class not working

how to hide base class property in c#
method hiding
c# new vs override
hiding in polymorphism
method hiding in c#
c# override
c# virtual method not overridden
c# hide property attribute

I'm trying to hide an event from an inherited class, but not via EditorBrowserable attribute. I have a DelayedFileSystemWatcher which inherits from FileSystemWatcher and I need to hide the Changed, Created, Deleted and Renamed events and make them private. I tried this, but it does not work:

    /// <summary>
    /// Do not use
    /// </summary>
    private new event FileSystemEventHandler Changed;

The XML comment is not showing in IntelliSense (the original info is shown). However, if I change the access modifier to public, the XML comment is shown in IntelliSense.

Any help is is welcome.

You don't want to use it but it trivially solves your problem:

class MyWatcher : FileSystemWatcher {
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
    private new event FileSystemEventHandler Changed;
    // etc..

The only other thing you can do is encapsulate it. Which is doable, the class just doesn't have that many members and you are eliminating several of them:

class MyWatcher : Component {
    private FileSystemWatcher watcher = new FileSystemWatcher();
    public MyWatcher() {
        watcher.EnableRaisingEvents = true;
        watcher.Changed += new FileSystemEventHandler(watcher_Changed);
        // etc..
    public string Path {
        get { return watcher.Path; }
        set { watcher.Path = value; }
    // etc..

Programming and Problem Solving with Visual Basic .NET, Overriding If you look at the definition of the Text property in the TextBox class in the table tells us every property, method, and event that is available in the class. Hiding When a derived class defines a property with the same name as One  If you are not explicitly specify "override" but use the same name, you simply hide the inherited member behind a completely different member and get the warning for that; you can suppress this warning with new. But you cannot override an event, so all you do is hiding. I don't see a reason for doing it in your case.

If you inherit it, you have to provide it.

Maybe instead of inheriting:

Public Class DelayedFileSystemWatcher : Component
  private FileSystemWatcher myFSW;

  public DelayedFileSystemWatcher
    myFSW = new FileSystemWatcher();

The Common Language Infrastructure Annotated Standard, 8.10.3 Property and Event Inheritance Properties and events are 8.10.4 Hiding, Overriding, and Layout There are two separate issues involved in base type (​hiding) and the sharing of layout slots in the derived class (overriding). Hiding is  I'd say the following rule could make sense for displaying the event in the "Event" Section: "If two defined events have the same identifier, do not duplicate the entries in the events section, but include docs (with pointers to the inherited event definition) for the actual module / class page".

You can't make something that's public in the base class into private in the derived class. If nothing else, it's possible to cast the derived class to the base class and use the public version.

The way you hide the base class's event actually works, but only from where the new event is visible, that is, from inside the derived class. From outside, the new event is not visible, so the base class's is accessed.

C# 5.0 Programmer's Reference, Notice how it uses the class instead of an instance to identify the event. (You can also avoid this problem if you don't use static events.) hiding. and. overriding. events. Events are a bit unusual because they are not inherited the same way The OverdraftAccount class can use the new keyword to hide the Overdrawn  The class Mustang inherits the method identifyMyself from the class Horse, which overrides the abstract method of the same name in the interface Mammal. Note: Static methods in interfaces are never inherited. Modifiers. The access specifier for an overriding method can allow more, but not less, access than the overridden method.

Differences Among Method Overriding, Method Hiding (New , No unread comment. loading. The "override" modifier extends the base class method, and the "new" modifier hides it. The "virtual" keyword modifies a method, property, indexer, or event declared in the base class and allows it to be If a method is not overriding the derived method then it is hiding it. Note. Do not declare virtual events in a base class and override them in a derived class. The C# compiler does not handle these correctly and it is unpredictable whether a subscriber to the derived event will actually be subscribing to the base class event.

Hide base class property in derived class, This is my Base class public class BaseClass { public string property1 { get; set; } abstract or virtual implementation of an inherited method, property, indexer, or event. PawarName); // not hidden } public class Pawar { public virtual System. class House : Building // DerivedClass inheritance at work The basic steps for overriding any event defined in the.NET Framework are identical and are summarized in the following list. To override an inherited event Override the protected On EventName method. Call the On EventName method of the base class from the overridden On EventName method, so that registered delegates receive the event.

Inheritance, Jun 29 - Jul 2, ONLINE EVENT What's the meaning of, Warning: Derived::f(char​) hides Base::f(double) ? For safety: to ensure that your class is not used as a base class (for example, to be sure that you can copy objects without fear of slicing). Although a virtual call seems to be a lot more work, the right way to judge  Hiding Properties. When you create a custom control (or any class), you inherit a lot of properties from the base class, most of which are fine. However, particularly in the case of a control derived from UserControl, this brings a lot of properties which may not be relevant to the new control.