如何与一个Knowntype属性的一类使用过时的属性时,忽略编译器警告 [英] How to ignore compiler warning when using Obsolete attribute on a class used with a Knowntype attribute

查看:227
本文介绍了如何与一个Knowntype属性的一类使用过时的属性时,忽略编译器警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,我们试图去precate我们的一些现有的类,并且已经开始将它们标记为过时的ObsoleteAttribute所以他们将停止使用。 ,使用与标有过时的属性,导致编译器警告,预计类型的KnownType属性的事实。然而,在我们的项目,我们有被视为错误的警告这样无视该警告是不是一种选择。有没有一个编译器指令晚饭preSS这样的警告?

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
    {

    }

编辑:我了解使用编译器指令忽略错误,但该编译器警告不会有一些

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

推荐答案

使用这只是问题的行之前禁用相应的警告:

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

#pragma warning disable 612, 618

和重新启用警告后:

#pragma warning restore 612, 618

奇怪的是,有是与此相关的2警告: CS0612 和的 CS0618 - 一个是 [作废] 和其他的 [过时(信息)] 。去图...

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

这篇关于如何与一个Knowntype属性的一类使用过时的属性时,忽略编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆