473,408 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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.StaticFunction(); // call to "uncallable" function
new Class().InstanceMethod(); // call to "uncallable" function
}
}
}

--
http://www.peterRitchie.com/
Feb 4 '06 #1
4 2710
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.StaticFunction(); // call to "uncallable" function
PR> new Class().InstanceMethod(); // 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.StaticFunction(); // call to "uncallable" function
PR> new Class().InstanceMethod(); // 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: AcYpx8QxEtsl1xq2Rqqnic9B+HGjqw==
X-WBNR-Posting-Host: 69.19.14.25
From: "=?Utf-8?B?UGV0ZXIgUml0Y2hpZQ==?=" <PR****@newsgroups.nospam>
Subject: Suppression of incorrect warnings.
Date: Sat, 4 Feb 2006 12:15:39 -0800
Lines: 29
Message-ID: <D7**********************************@microsoft.co m>
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.public.dotnet.languages.csharp
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:383468
X-Tomcat-NG: microsoft.public.dotnet.languages.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.StaticFunction(); // call to "uncallable" function
new Class().InstanceMethod(); // 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.StaticFunction(); // call to "uncallable" function
PR> new Class().InstanceMethod(); // 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
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...
3
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
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...
30
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
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...
10
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...
6
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
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...
1
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.