c# - NativeMethods 类是在 .NET 中专门处理的吗?

标签 c# .net pinvoke native-methods

https://msdn.microsoft.com/en-us/library/ms182161.aspx

本页中描述的三个类是否在 .NET Framework 中进行了特殊处理? (NativeMethods、SafeNativeMethods 和 UnsafeNativeMethods)

我问的原因是我想知道是否可以创建 NativeMethods 类的类别。例如:

ComNativeMethods
User32NativeMethods
OleStorageNativeMethods

最佳答案

这是约定,不是要求。如果您反射(reflection) CLR 并查看其中的代码,您会经常在 NativeMethods 类中看到 P/Invoke 代码。我相信 FxCop 如果遇到它,会建议将您的 P/Invoke 代码放在这样的类中。

关于c# - NativeMethods 类是在 .NET 中专门处理的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1445117/

相关文章:

c# - 在不知道数组大小的情况下从 C 到 C# P/Invoke

c# - 在 Windows CE 6.0 CF.NET 2.0 上删除 ARP 条目

c# - 按单词拆分音频文件

c# - 枚举一个 IDictionary.Keys 集合,它是一个 ICollection<T>

c# - FluentValidation 和 Entity Framework 查找

c# - 将导航属性设置为 null 不会保存到数据库

.net - 异构字典,但类型化?

c# - 在 Newtonsoft JSON.NET 模式中禁用空类型

c# - 使用进程间同步对象同步 2 个进程 - Mutex 或 AutoResetEvent

C# winforms : How to change DPI of the System. Drawing.BItmap?