I've this warning because I've created the type :
#if COMPACT_FRAMEWORK_3_5
namespace System.Diagnostics
{
/// <summary>Determines how a class or field is displayed in the debugger variable windows.</summary>
/// <remarks>See : http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerdisplayattribute.aspx </remarks>
[AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
[ComVisible(true)]
public sealed class DebuggerDisplayAttribute : Attribute
{ /* ... */ }
}
#endif
I've created it because I'm on CF.NET and this attribute doesn't exists in it, so I created it in开发者_JS百科 order to customize my debug view (I always debug using CF.NET).
I've tried to add #pragma warning disable
at the beginning and restore it at the end but doesn't work, I've always a CS0444 warning in VS2k8 ...
How can I fix this?
Thanks
EDIT
I used it like this :
#if COMPACT_FRAMEWORK_3_5
#pragma warning disable // 0444
namespace System.Diagnostics
{
/// <summary>Determines how a class or field is displayed in the debugger variable windows.</summary>
/// <remarks>See : http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerdisplayattribute.aspx </remarks>
[AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
[ComVisible(true)]
public sealed class DebuggerDisplayAttribute : Attribute
{ /* ... */ }
}
#pragma warning restore // 0444
#endif
Your example has the number commented out:
#pragma warning disable // 0444
Eh, don't:
#pragma warning disable 444
To disable it globally, you use /nowarn:444
(comma-separate other warnings to disable) with the compiler. If using an IDE there'll probably be somewhere in the project properties to set warnings to disable (Visual Studio has it on the "Build" tab, SharpDevelop has it on the "Compiling" tab, other IDEs will likely have it somewhere similar). Nant scripts have a <onwarn>
element as an allowed child of <csc>
(which also has a nowarn
attribute, but that's deprecated).
I'd avoid global disabling though, after all, doing something that triggers CS0444 is normally a bad idea. In your case above you've a good reason for doing so (you need functionality the compact version doesn't give you) and know that's what you are doing, but if you'd accidentally done it somewhere else, and you'd suppressed warnings, you'll be none the wiser.
Edit: For that matter, I've a policy that I never disable a warning without at least a short comment as to why. An uncommented disabling of a warning can mean "I did something silly here, and then disabled the warning rather than fixed it", the comment can make it clear that this isn't the case, and that there's nothing in need of a fix.
Ermm, perhaps try
#pragma warning disable 444
instead of commenting the error number? See here of course
精彩评论