[英]Do I need to create separate classes for request and response C#?
how to make the parameters of the function or class? 如何制作函数或类的参数?
var list = await _service.GetAllNewsByParams( new NewsGetAllParams
{
Category = 1,
From = _From,
OrderBy = _OrderBy,
Page = _Page,
To = _To
});
or 要么
var list = await _service.GetAllNewsByParams(
_To,
_OrderBy,
_From, _Page,
_SeletedNewsTagId);
and Do I need to create a class for each method in service 我是否需要为服务中的每个方法创建一个类
public async Task<IList<NewsSentimentIndexes>> getNewsSentimentIndexes()//new class NewsSentimentIndexes
public async Task<IList<News>> getNewsSentimentIndexes()//new class News
public async Task<IList<NewsSomeNewClass>> getNewsSentimentIndexes()//new class for exmaple
Well, as I can see in your parameters, it has some parameters belong to the data itself (eg item ids, names etc) and some parameters belong to the query (eg from/to, order by, page, take etc). 好吧,正如我在您的参数中看到的那样,它有一些参数属于数据本身(例如,项目ID,名称等),而一些参数属于查询(例如,从/至,按顺序,按页,采用等)。
So, I would say that you can use the parameters directly or create the classes for it. 因此,我想说您可以直接使用参数或为其创建类。 It's up to you.
由你决定。
Just keep in mind that if you will have, let's say, 10 parameters, and some of them will be optional, it could lose the readability (it's just my thoughts). 请记住,如果您有10个参数,其中一些是可选参数,则可能会失去可读性(这只是我的想法)。
In case with classes, you will be able to create the class hierarchy, where base class could contain some parameters which is in use for different endpoints. 对于类,您将能够创建类层次结构,其中基类可以包含一些用于不同端点的参数。
I think, that the same could be applied to classes that will be used to return the data. 我认为,可以将相同的方法应用于将用于返回数据的类。
Hope it will help. 希望它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.