命名空间组织和约定
所以我有一点问题。我使用 StackOveflow API 从事 C# 项目。您可以像这样向它发送请求:
http://stackoverflow.com/users/rep/126196/2010-01-01/2010-03-13
并返回类似 JSON 响应的内容:
[{"PostUrl":"1167342",
"PostTitle":"Are ref and out in C# the same a pointers in C++?",
"Rep":10},
{"PostUrl":"1290595",
"PostTitle":"Where can I find a good tutorial on bubbling?",
"Rep":10}
...
所以我的问题是我有一些像 GetJsonResponse()
这样的方法,它返回上面的 JSON 和 SaveTempFile()
将该 JSON 响应保存到临时文件以供以后使用。我不确定是否应该为它们创建一个类,或者将它们放在哪个命名空间下。现在我当前的命名空间层次结构如下:StackOverflow.Api.Json
。那么我应该如何组织这些方法/类/命名空间呢?
So I have a little bit of a problem. I working on a project in C# using The StackOveflow API. You can send it a request like so:
http://stackoverflow.com/users/rep/126196/2010-01-01/2010-03-13
And get back something like this JSON response:
[{"PostUrl":"1167342",
"PostTitle":"Are ref and out in C# the same a pointers in C++?",
"Rep":10},
{"PostUrl":"1290595",
"PostTitle":"Where can I find a good tutorial on bubbling?",
"Rep":10}
...
So my problem is that I have some methods like GetJsonResponse()
which return the above JSON and SaveTempFile()
which saves that JSON response to a temporary file for later use. I not sure if I should create a class for them, or what namespace to put them under. Right now my current namespace hierarchy is like so: StackOverflow.Api.Json
. So how should I organize these methods/classes/namespaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您有一个代表站点的类,它知道所涉及的 URL 等,然后是一个方法,例如
GetReputationChanges(int userId, DateTime from, DateTime to)
。这可以返回一个帖子列表(其中一个帖子是另一个类)。IMO,所有这些都应该位于同一个命名空间中。
我已经为我的声誉跟踪器准备了一些 - 我不知道这到什么程度已内置于 Kevin 构建的 API 中。您知道他们正在开发官方 API,对吗?
I would suggest you have a class representing a site, which knows about the URLs involved etc, then a method such as
GetReputationChanges(int userId, DateTime from, DateTime to)
. That can return you a list of posts (where a post is another class).All of this should be in the same namespace, IMO.
I have some of this already for my Reputation Tracker - I don't know to what extent this has already been built into the API that Kevin has built. You're aware that they're working on an official API though, right?