在 C# 中公开 DLL 的方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/652395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exposing the methods of a DLL in C#
提问by xarzu
After someone creates a DLL in C# using the Microsoft Visual development environment, how would another programmer take that code, make a new project that includes the DLL's source and make a GUI that uses the DLL'S API?
在有人使用 Microsoft Visual 开发环境在 C# 中创建了一个 DLL 之后,另一个程序员将如何获取该代码、创建一个包含 DLL 源代码的新项目并创建一个使用 DLL 的 API 的 GUI?
I have already done the following four steps:
我已经做了以下四个步骤:
1) In the Solution Explorer right-click "References" and select "Add Reference ...".
1) 在解决方案资源管理器中右键单击“引用”并选择“添加引用...”。
2) Select the "Browse" tab.
2) 选择“浏览”选项卡。
3) Navigate to the DLL and select it.
3) 导航到 DLL 并选择它。
4) Add the appropriate "using" directive to the top of the code.
4) 在代码顶部添加适当的“using”指令。
What is next? After I declare a new object, how do I see what methods to use?
接下来是什么?声明新对象后,如何查看要使用的方法?
采纳答案by Quintin Robinson
View Menu -> Object Browser
查看菜单 -> 对象浏览器
You should be able to look at the objects/methods and so on contained in the DLL and publicly exposed.
您应该能够查看包含在 DLL 中并公开暴露的对象/方法等。
回答by Ed S.
You should be able to use intellisense and the object explorer as always. Without the source that will be your best bet.
您应该能够像往常一样使用智能感知和对象资源管理器。如果没有来源,那将是您最好的选择。
回答by Martin Marconcini
Well...
好...
Suppose your library is called MyLib.DLL
假设您的库名为 MyLib.DLL
You would do:
你会这样做:
MyLib ml = new MyLib();
ml.YourMethodsShouldAppearHere(); //If they are public of course.
;)
;)
回答by Lancelot
I don't have any code off the top of my head but have you investigated the Reflection library? You should be able to figure out and run everything you need with that...
我的脑子里没有任何代码,但你调查过反射库吗?你应该能够弄清楚并运行你需要的一切......
回答by Andy White
You can open any .NET DLL in this 3rd party tool called ".NET Reflector". This tool will allow you to view all the types/methods/properties and even decompile the code contained in the DLL.
您可以在这个名为“ .NET Reflector”的第三方工具中打开任何 .NET DLL 。该工具将允许您查看所有类型/方法/属性,甚至可以反编译 DLL 中包含的代码。
.NET Reflector is similar to the object browser in Visual Studio, but is way more powerful.
.NET Reflector 类似于 Visual Studio 中的对象浏览器,但功能更强大。
If you haven't tried Reflector yet, I highly recommend it (it's really easy to use)!
如果你还没有尝试过 Reflector,我强烈推荐它(它真的很容易使用)!
回答by Jon Erickson
you can load the DLL via the .NET Reflector tool from red-gate and see all of the api and even how it was implemented http://www.red-gate.com/products/reflector/
您可以通过 red-gate 的 .NET Reflector 工具加载 DLL 并查看所有 api 甚至它是如何实现的http://www.red-gate.com/products/reflector/

