Compartir a través de


C# Featurette #2 - Inline Warning Control

Another feature that we added for Whidbey is the ability to selectively disable warnings within your code. For example:

#pragma warning disable 135

  // Disable warning CS135 in this block

#pragma warning restore 135

Comments

  • Anonymous
    April 12, 2004
    Cool feature. Not sure where I would use it, except maybe to disable warnings about XML documentation not being on a public member for a few autogenerated classes. coughXSD.execough

    I don't suppose there is a way to selectively choose which exceptions the IDE will "break when thrown" on a per assembly/class/file basis using pragmas is there?

    My example is our collab partners have some code that throws 30-40 FileNotFoundExceptions that I would love to be able to ignore since it's "handled", but I would still like to break when thrown for that exception with all the rest of our code.

  • Anonymous
    April 12, 2004
    Good feature, but I think its general use should be discouraged - warnings are GOOD, and you should indever to fix your code, not just block them out....

    :)

    But, you can't always :)

  • Anonymous
    April 12, 2004
    So when can I disable compiler errors like missing type casts? Those are not really not errors as the compiler will bark at truly incompatible type casts. Note: I am talking about casting, not converting.

  • Anonymous
    April 12, 2004
    I'll definitely be using this feature for a few cases where I'll never use some features of a class I've declared.

    For example, I have some interfaces which contain events. Some of the implementations of a particular interface will never fire those events, so the compiler generates a warning.

    Now I come to think of it, I probably should have used abstract classes rather than interfaces.

  • Anonymous
    April 12, 2004
    The comment has been removed

  • Anonymous
    April 12, 2004
    re: DataSet?XML????

  • Anonymous
    April 13, 2004
    Why is the syntax different than the same pragma for the C++ compiler?

    The syntax I'm accustomed to looks like this:
    <code>
    #pragma warning(enable : 4244)
    </code>

  • Anonymous
    April 14, 2004
    I suggest that Microsoft could extend the syntax of C# to allow checked and unchecked wherever unsafe is allowed.

  • Anonymous
    April 21, 2004
    Hooray!

    The place I most want to use this is the stupid requirement to have XML comments on members of a public enumeration. For things like:

    /// <summary>
    /// Marital Status
    /// (Do not use as Filing Status)
    /// </summary>
    public enum MaritalStatus
    {
    Single,
    Married,
    Divorced,
    Widowed
    };

    Where we'd get 4 warnings because C#'s compiler wants me to put an XML comment to explain the difference between "Married" and "Divorced", etc..

  • Anonymous
    May 17, 2004
    I think this feature is useful. I am generally against disabling warnings, however, in this case I added to my project (which requires XML documentation) a class that I downloaded from the Internet. The issue is that this class did not provide such documentation. At the meantime, I didn't want to do a lot of modifications to the class in order to make it easy to get upgrades in the future. In the meantime, what I will do now is to send the author a comment to support provide the XML documentation to avoid this issue.

    Like any other tool, it can be useful when used appropriately, so irrespective of the exact scenarios, I think it makes sense to have this feature available.

  • Anonymous
    May 20, 2004
    Great! One of my classes has properties whose values are set only through reflection, and the compiler is always giving me "warning CS0649: Field 'CommandLineParser.ParserTest.PrivateInstanceArg' is never assigned to, and will always have its default value null.' In this case the warning is essentially wrong, but the compiler can't tell that. I'd love to disable those warnings.

  • Anonymous
    December 18, 2004
    Helpful For MBA Fans.

  • Anonymous
    December 27, 2004
    [http://itpeixun.51.net/][http://aissl.51.net/][http://kukuxz003.freewebpage.org/][http://kukuxz001.51.net/][http://kukuxz003.51.net/][http://kukuxz005.51.net/][http://kukuxz002.51.net/][http://kukuxz004.freewebpage.org/][http://kukuxz007.51.net/][http://kukuxz001.freewebpage.org/][http://kukuxz006.51.net/][http://kukuxz002.freewebpage.org/][http://kukuxz004.51.net/][http://kukuxz008.51.net/][http://kukuxz009.51.net/][http://kukuxz005.freewebpage.org/][http://kukuxz006.freewebpage.org/][http://kukuxz007.freewebpage.org/][http://kukuxz009.freewebpage.org/]

  • Anonymous
    June 07, 2009
    PingBack from http://greenteafatburner.info/story.php?id=4858

  • Anonymous
    June 08, 2009
    PingBack from http://quickdietsite.info/story.php?id=14364

  • Anonymous
    June 13, 2009
    PingBack from http://thestoragebench.info/story.php?id=10834