문제

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