Selectively suppress custom Obsolete warnings

Use #pragma warning disable:

using System;

class Test
{
    [Obsolete("Message")]
    static void Foo(string x)
    {
    }

    static void Main(string[] args)
    {
#pragma warning disable 0618
        // This one is okay
        Foo("Good");
#pragma warning restore 0618

        // This call is bad
        Foo("Bad");
    }
}

Restore the warning afterwards so that you won’t miss “bad” calls.

Leave a Comment