简体   繁体   English

我是否需要为请求和响应C#创建单独的类?

[英]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.

相关问题 C#中的Testdriven Remoting - 我需要一个单独的服务器AppDomain吗? - Testdriven Remoting in C# - Do I need a separate server AppDomain? 我需要在 API 响应中接受 ExtensionDataObject 吗? C# - Do i need to accept ExtensionDataObject in API response? C# c#异步卷曲请求 - 如何访问响应? - c# Async curl request - how do I access the response? 如何发出 HTTP 请求,然后在 C# 中等待响应 - How do I make an HTTP request and then wait for a response in C# 如何在c#中的静态类中创建一个简单的回调 - How do I create a simple callback in static classes in c# C#do嵌套类需要实例化吗? - C# do nested classes need to be instantiated? 如何在我对Get请求的响应中使用c#创建multipart / form-data类型的内容 - How do I create the content of type multipart/form-data using c# as part of my response to Get request 我需要什么才能在 c# 中使用统一创建音频可视化工具 - What do i need to be create an audio visualizer in c# with unity 我是否需要 C# 来创建要在 IronPython 中使用的 dll? - Do I need C# to create a dll to be used in IronPython? 我需要分开业务对象和业务逻辑吗? C#中具有存储库模式的Asp.net MVC - Do I need to Separate Business Objects and Business Logic? Asp.net MVC with Repository Pattern in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM