如何开始在 .NET 中创建应用程序 API [英] How to start creating an application API in .NET

查看:30
本文介绍了如何开始在 .NET 中创建应用程序 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我工作的公司中,我们有一个用 .NET 开发的桌面应用程序,我们希望为其他软件开发人员开放一些部分.

In the company I work for we have a desktop application developed in .NET that we like to open up some parts for other software developers.

我认为它就像其他软件可以访问的某种公共方法.是否有任何标准方法、最佳做法或其他相关经验?

I see it like some kind of public methods that other software can access. Is there any standard approach, best practices or other experience of this?

我想你可以通过 Win32 调用、C/C++ 编程等来做到这一点.但我主要是一名 .NET 开发人员,并且在主要是 VB.NET 和一些 C# 方面有多年的编程经验.我希望在 .NET 中找到一种方法来做到这一点.但它应该可以被其他语言开发的软件访问.

I guess you could do this with Win32 calls, C/C++ programming etc. But I'm mainly a .NET developer and have some years of experience programmming in mainly VB.NET but also some C#. I hope finding a way to do this within .NET. But it should be accessible for software developed in other languages.

最好的问候/马格努斯

推荐答案

有两种方法可以解决这个问题.第一个涉及使用插件/模块模式.从这里开始.

There are two ways to go about this. The first involves using the Plug In / Module pattern. Start here for that.

第二种方法是通过记录良好的程序集简单地公开您的 API 逻辑.

A second way is to simply expose your API logic through well documented assemblies.

您选择的方式实际上归结为您希望它如何实施.例如,Adobe Photoshop 在很大程度上使用了插件模式.MS Office 使用插件并提供对象接口来处理应用程序.

The way you pick really boils down to how you want it implemented. For example, Adobe Photoshop uses the plug-in pattern to great extent. MS Office uses both plug-ins as well as provides an object interface for working with the application.

更新:.Net 程序集中的对象可以公开以供外部应用程序使用,只需将对象范围设置为 Public.这包括窗体、业务对象、枚举等.

UPDATE: Objects in .Net assemblies can be exposed to be consumed by external applications simply by setting the objects scope to Public. This includes windows forms, business objects, enum's, etc.

请从外部开发人员的角度考虑.他们需要哪些信息才能成功扩展/控制您的产品?不管是什么,把它放在帮助文件中.

Just think about it from the external developer's perspective. What information will they need to have in order to be successful at extending / controlling your product? Whatever that is, put it in the help file.

此外,请利用 .Net 的自动文档功能.这包括添加 IDE 已经知道如何通过智能感知读取和显示的 xml 文档.例如:

Also, make use of the auto-documentation features of .Net. This includes adding xml documentation the the IDE already knows how to read and display via intellisense. For example:

/// <summary>
/// Gets all active documents for the specified customer.
/// </summary>
/// <param name="customerId">The Id of the customer.</param>
/// <returns>A list of documents for this customer.</returns>
public static List<Document> GetDocuments(int customerId)
{
    //... do something ...
}

这篇关于如何开始在 .NET 中创建应用程序 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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