Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore compiler warning when using Obsolete attribute on a class used with a KnownType attribute

So we are trying to deprecate some of our existing classes, and have started marking them as obsolete with the ObsoleteAttribute so they will stop being used. The fact that using the KnownType attribute with a type that is marked with the Obsolete attribute and is causing a compiler warning is expected. However, in our project we have warnings treated as errors so ignoring the warning isn't an option. Is there a compiler directive to suppress this warning?

The following usage causes a compiler warning:

///ProductTemplateDataSet is marked with the Obsolete attribute [KnownType(typeof(ProductTemplateDataSet))] public class EntityCollectionBase : System.Data.DataSet { } 

Edit: I understand using compiler directives to ignore errors, but this compiler warning doesn't have a number.

like image 654
Jace Rhea Avatar asked Mar 11 '11 15:03

Jace Rhea


1 Answers

Use this to disable the corresponding warnings just before the offending line:

#pragma warning disable 612, 618 

And reenable the warnings after it:

#pragma warning restore 612, 618 

Curiously enough, there're 2 warnings related to this: CS0612 and CS0618 - one is for [Obsolete] and the other for [Obsolete("Message")]. Go figure...

like image 199
Jordão Avatar answered Sep 20 '22 19:09

Jordão