473,785 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Suppression of incorrect warnings.

Does anyone know how to suppress a specific warning for a line or block of
code in C#? C++ has a nice facility to disable a warning for a block of code
with #pragma for warnings that are incorrect or don't apply.

For example, the following code generates an CS0628 because CS0628 makes an
incorrect assumption that "protected" applies only to inheritance:

public sealed class Class
{
EmbeddedClass utility = new EmbeddedClass() ;

protected static void StaticFunction( ) // CS0628
{
}
protected void InstanceMethod( ) // CS0628
{
}
private class EmbeddedClass
{
public EmbeddedClass()
{
Class.StaticFun ction(); // call to "uncallable " function
new Class().Instanc eMethod(); // call to "uncallable " function
}
}
}

--
http://www.peterRitchie.com/
Feb 4 '06 #1
4 2757
Hello Peter,

What's the reason to use protected members in that case?

PR> Does anyone know how to suppress a specific warning for a line or
PR> block of code in C#? C++ has a nice facility to disable a warning
PR> for a block of code with #pragma for warnings that are incorrect or
PR> don't apply.
PR>
PR> For example, the following code generates an CS0628 because CS0628
PR> makes an incorrect assumption that "protected" applies only to
PR> inheritance:
PR>
PR> public sealed class Class
PR> {
PR> EmbeddedClass utility = new EmbeddedClass() ;
PR> protected static void StaticFunction( ) // CS0628
PR> {
PR> }
PR> protected void InstanceMethod( ) // CS0628
PR> {
PR> }
PR> private class EmbeddedClass
PR> {
PR> public EmbeddedClass()
PR> {
PR> Class.StaticFun ction(); // call to "uncallable " function
PR> new Class().Instanc eMethod(); // call to "uncallable "
PR> function
PR> }
PR> }
PR> }
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Feb 4 '06 #2
Hello Peter,

You can use
#pragma warning disable 0628
#pragma warning restore
at least
PR> Does anyone know how to suppress a specific warning for a line or
PR> block of code in C#? C++ has a nice facility to disable a warning
PR> for a block of code with #pragma for warnings that are incorrect or
PR> don't apply.
PR>
PR> For example, the following code generates an CS0628 because CS0628
PR> makes an incorrect assumption that "protected" applies only to
PR> inheritance:
PR>
PR> public sealed class Class
PR> {
PR> EmbeddedClass utility = new EmbeddedClass() ;
PR> protected static void StaticFunction( ) // CS0628
PR> {
PR> }
PR> protected void InstanceMethod( ) // CS0628
PR> {
PR> }
PR> private class EmbeddedClass
PR> {
PR> public EmbeddedClass()
PR> {
PR> Class.StaticFun ction(); // call to "uncallable " function
PR> new Class().Instanc eMethod(); // call to "uncallable "
PR> function
PR> }
PR> }
PR> }
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Feb 4 '06 #3
Hi,
Welcome to MSDN Newsgroup!

There is a " #pragma warning" C# Preprocessor Directive in C# 2.0 , we
could use it to disable specified warning. You could refer to the following
article:
Title: #pragma warning (C# Reference)
URL:http://msdn2.microsoft.com/441722ys.aspx

I hope the above information is helpful for you. Thanks and have a nice day!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
Thread-Topic: Suppression of incorrect warnings.
thread-index: AcYpx8QxEtsl1xq 2Rqqnic9B+HGjqw ==
X-WBNR-Posting-Host: 69.19.14.25
From: "=?Utf-8?B?UGV0ZXIgUml 0Y2hpZQ==?=" <PR****@newsgro ups.nospam>
Subject: Suppression of incorrect warnings.
Date: Sat, 4 Feb 2006 12:15:39 -0800
Lines: 29
Message-ID: <D7************ *************** *******@microso ft.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
Xref: TK2MSFTNGXA02.p hx.gbl microsoft.publi c.dotnet.langua ges.csharp:3834 68
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp

Does anyone know how to suppress a specific warning for a line or block of
code in C#? C++ has a nice facility to disable a warning for a block of codewith #pragma for warnings that are incorrect or don't apply.

For example, the following code generates an CS0628 because CS0628 makes anincorrect assumption that "protected" applies only to inheritance:

public sealed class Class
{
EmbeddedClass utility = new EmbeddedClass() ;

protected static void StaticFunction( ) // CS0628
{
}
protected void InstanceMethod( ) // CS0628
{
}
private class EmbeddedClass
{
public EmbeddedClass()
{
Class.StaticFun ction(); // call to "uncallable " function
new Class().Instanc eMethod(); // call to "uncallable " function
}
}
}

--
http://www.peterRitchie.com/


Feb 5 '06 #4
Sorry, somehow I got in my head that in-line classes could only access
protected members of the containing class.

Ignore me. Switching to private from protected gets rid of the warning and
avoids the inheritance implication.

--
http://www.peterRitchie.com/
"Michael Nemtsev" wrote:
Hello Peter,

What's the reason to use protected members in that case?

PR> Does anyone know how to suppress a specific warning for a line or
PR> block of code in C#? C++ has a nice facility to disable a warning
PR> for a block of code with #pragma for warnings that are incorrect or
PR> don't apply.
PR>
PR> For example, the following code generates an CS0628 because CS0628
PR> makes an incorrect assumption that "protected" applies only to
PR> inheritance:
PR>
PR> public sealed class Class
PR> {
PR> EmbeddedClass utility = new EmbeddedClass() ;
PR> protected static void StaticFunction( ) // CS0628
PR> {
PR> }
PR> protected void InstanceMethod( ) // CS0628
PR> {
PR> }
PR> private class EmbeddedClass
PR> {
PR> public EmbeddedClass()
PR> {
PR> Class.StaticFun ction(); // call to "uncallable " function
PR> new Class().Instanc eMethod(); // call to "uncallable "
PR> function
PR> }
PR> }
PR> }


Feb 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2211
by: Kylotan | last post by:
I have the following code: def IntToRandFloat(x): """Given a 32-bit integer, return a float in """ x = int(x) x = int(x << 13) ^ x return (1.0-((x*(x*x*15731+789221)+1376312589)&0x7fffffff)/1073741824.0) Basically it's a function directly copied from a C implementation. Now
3
5791
by: Terry Richards | last post by:
mysql 4.1.9-standard how do i find exactly what the warnings are when i only get Query OK, 1 row affected, 1 warning (0.00 sec) :-)^2
1
14537
by: AMDRIT | last post by:
The stuff below seems to work, when I am applying the logic for suppression. However, it doesn't work when suppressing row data. Any Ideas? Basically, if there is only one row of data, I need to suppress a caption and it corresponding data field. Create a formula field @RowCount Formula Field
30
2193
by: prasanna | last post by:
i will be very thankful if you sent all the errors and warnings regarding to the language C thank you
22
8324
by: John Fisher | last post by:
void f(int p) { } Many (most?) compilers will report that p is unreferenced here. This may not be a problem as f may have to match some common prototype. Typically pointers to functions are involved. For a long time I have used
10
2107
by: Duncan Muirhead | last post by:
When I compile the program below "Program start" with gcc -std=c99 -pedantic -o bgcc bgcc.c (where gcc --version gives gcc (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2) Copyright (C) 2004 Free Software Foundation, Inc. ) I get the warning bgcc.c:3: warning: "struct thingTag" declared inside parameter list bgcc.c:3: warning: its scope is only this definition or declaration, which is probably not what you want
6
1913
by: pete142 | last post by:
When I compile this code: typedef unsigned char BYTE; BYTE * IpString(unsigned int ip) { static BYTE ipString; ipString = (BYTE) 0xff & (ip >24); ipString = (BYTE) 0xff & (ip >16);
3
3198
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with /W3 I get warnings that with /W4 are shown as remarks, e.g.: warning #177: variable "Foo" was declared but never referenced ....is displayed as a "remark #177" with /W4. That doesn't fit the
1
2518
by: Robert Singer | last post by:
Platform: winXP, excel 2003 Python 2.5.2 XLWriter 0.4a3 (http://sourceforge.net/projects/pyxlwriter/) Is anyone here using this very nice package, for writing excel files? I'm using it on python 2.5.2. (although it is made for older version of python) and cannot find a way to get rid of this error (code and errors below). Does anyone know how to avoid it ? I would appreciate all help and
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.