Generic interface problem

别说谁变了你拦得住时间么 提交于 2019-12-07 06:04:27

Maybe Im miss-understanding you, but couldnt you make a super class that all of your DTO's like BaseDTO

Then use it like so:

public class CustomerDTO : BaseDTO {}

IDataForGrid<BaseDTO> aa;

var coll = aa.GetList();

This way, your coll variable will be of type IGridResponse<BaseDTO> which all of your DTO object extend from.

That make sense?

You can make the method generic as well so that T can be substituted as required:

public class Service1
{
  public IGridResponse<T> CreateResponse<T>(IGridRequest request)
  {
    ...
    IDataForGrid<T> aa;

    if(request == 1) cg = new CustomerGridData;
    if(request == 2) og = new OrderGridData;

    var coll = aa.GetList();
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!