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.

有帮助吗?

解决方案

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;}
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top