-2

I have an abstract class which has an event (abstract). I do not need actually this event in my implementation. When I dont use it in my implementation, it gives well warning, which I dont want to have.. Is there any c# predefine annotation like [unused] or [ignore] to prevent getting warning?

public abstract class Abc
{
 ...
 public abstract event EventHandler<MsgEventHandler> 
}

public MyClass: Abc
{
   public override event EventHandler<MsgEventHandler> MesReceived;


//constructers
//methodes
//etc

}
Wolfgang
  • 91
  • 6
  • 4
    Does `public abstract event EventHandler` compile for you? – mjwills Oct 27 '17 at 12:49
  • Your code is invalid. Why is the event even abstract? It makes no sense. – ProgrammingLlama Oct 27 '17 at 12:50
  • 3
    An abstract class is not required to have everything abstract. The recommended pattern is to simply implement the event in the base class, and provide a `protected virtual` method to actually invoke the event. Overriding this is optional. Very few classes have a need to do the event handler implementation themselves. – Jeroen Mostert Oct 27 '17 at 12:51

2 Answers2

2

Add

#pragma warning disable 0067

before the declaration of the abstract event handler. Do not forget to restore it. This should probably work for you:

public class MyClass: Abc
{
#pragma warning disable 0067
    public override event EventHandler<EventArgs> MesReceived;
#pragma warning restore 0067
}
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Sjips
  • 1,248
  • 2
  • 11
  • 22
1

The whole point of abstract keyword is that you must implement it in a derived class. Consider abstract property as an interface member that you should implement on inheriting from it. If you do not always have to implement this logic and want to leave it empty use virtual keyword instead:

public abstract class Abc
{
   public virtual event EventHandler<MsgEventHandler> MesReceived;
}

public MyClass: Abc
{       
   // compiles without this line:
   public override event EventHandler<MsgEventHandler> MesReceived;
}
Ivan Yurchenko
  • 3,762
  • 1
  • 21
  • 35