代码分析CA1060修复 [英] Code Analysis CA1060 Fix
问题描述
我的应用程序中包含以下代码:
I have the following code in my application:
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int x, int y, int width, int height, uint flags);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hwnd, uint msg,
IntPtr wParam, IntPtr lParam);
我从代码分析(FxCop)中收到以下警告:
I am getting the following warning from Code Analysis (FxCop):
CA1060:Microsoft.Design:由于它是P / Invoke方法,因此应在类$中定义
'IconHelper.GetWindowLong(IntPtr,int)'。 b $ b名为NativeMethods,SafeNativeMethods或UnsafeNativeMethods。
CA1060 : Microsoft.Design : Because it is a P/Invoke method, 'IconHelper.GetWindowLong(IntPtr, int)' should be defined in a class named NativeMethods, SafeNativeMethods, or UnsafeNativeMethods.
有人可以告诉我应该将它们放在哪个类中吗?我不知道它是Native,SafeNative还是UnsafeNative。
Can someone tell me which class I should put them in? I don't know if it is Native, SafeNative, or UnsafeNative.
推荐答案
您在此处有关于此警告的详细信息:< a href = http://msdn.microsoft.com/en-us/library/ms182161.aspx> http://msdn.microsoft.com/en-us/library/ms182161.aspx 。简而言之:
You have detailed information about this warning here: http://msdn.microsoft.com/en-us/library/ms182161.aspx. In short:
对于大多数应用程序而言,将P / Invokes移至名为NativeMethods的新类就足够了。
For most applications, moving P/Invokes to a new class that is named NativeMethods is enough.
这篇关于代码分析CA1060修复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!