如何在C#中的API? [英] How to create an APi in C#?

查看:166
本文介绍了如何在C#中的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做节目,但现在我面临的一个挑战。我在一个项目中,我要创建在C#的API为我的用户。其基本过程是,我有一个C#code,我正在读一个XML文件,并获得对标签的属性和值。我实现了,现在我要创建消耗品的API相同的功能。 有没有什么办法,通过它我可以学习创建API?

I have been doing programming, but now I'm facing a challenge. I'm on a project where I have to create an API in C# for my users. The basic process is that I have a C# code where I'm reading an XML file and obtaining the attributes and values that are between the tags. I achieved that and now I have to create consumable API for the same functionality. Is there any way through which I can learn to create API?

基本上,我没有对如何使用API​​前进的想法。例子任何形式将是很好的利用了我。

Basically I dont have any idea on how to move on with API. Any sort of examples would be of good use to me.

推荐答案

这是API,不过是为其他程序员与你的code接口。 C#类库可能是一个API,因为可以一个Web服务,一个WCF终结等方面做出一种是创建一个C#类库项目最简单的方法,确保它有公共方法,并将其编译为.dll你可以发布。

An API is just a way for other programmers to interface with your code. A C# class library could be an API, as could a web service, a WCF endpoint, etc. The easiest way to make one is to create a C# Class Library project, make sure it has public methods, and compile it to a .dll which you can distribute.

正如其他人所说,该框架设计指南对于一些规律可循有用的。

As mentioned by others, the Framework Design Guidelines are useful for some rules to follow.

有一件事要记住 - 我希望这将得到敲定所有新的软件开发人员 - 是API设计本质上是一个可用性问题。你正在构建的软件的用户界面,和你的用户是其他程序员。

One thing to keep in mind - and I wish this would get hammered into all new software developers - is that API design is fundamentally a usability problem. You're building a UI for the users of your software, and your users are other programmers.

这意味着你要遵循的UI / UX设计的所有的一般原理 - 可发现,使共同的任务简单等特点。

This means that you want to follow all the general principals of UI/UX design - discoverability, making common tasks simple, etc.

取XML注释的优势,以确保文件是永远存在的。确保最常见的任务很容易执行,而且很明显如何做到这一点。使异常干净,包括有用的,可操作的错误消息。想想什么使消费者的生活更轻松。

Take advantage of XML comments to make sure the documentation is always there. Be sure that the most common tasks are easy to perform and that it's obvious how to do so. Make exceptions clean and include useful, actionable error messages. Think about what would make the consumer's life easier.

这篇关于如何在C#中的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆