Question

Say I have this classes that derived from EventArgs

public class myclass01:EventArgs
{
  public string channel{get;set;}
  public string generic_property{get;set;}
}

public class myclass02:EventArgs
{
  public string extension{get;set;}
  public string generic_property{get;set;}
}

How can I make it so that I don't have to define "generic_property" over and over again on classes that derived from EventArgs? Sort of like I will have a base class that has all my generic properties.

Was it helpful?

Solution

You can create a class that is derived from EventArgs, which you use as the base for all your custom classes. This class should be abstract if you don't want it to be useable directly.

public abstract class MyCommonEventBase : EventArgs
{
  public string generic_property { get; set; }
}

public class myclass01 : MyCommonEventBase
{
  public string channel{get;set;}
}

public class myclass02 : MyCommonEventBase
{
  public string extension{get;set;}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top