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

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

问题描述

因此,我们正在尝试弃用一些现有的类,并已开始使用 ObsoleteAttribute 将它们标记为已过时,以便停止使用它们.预期将 KnownType 属性与标记为 Obsolete 属性的类型一起使用并导致编译器警告的事实.但是,在我们的项目中,我们将警告视为错误,因此不能选择忽略警告.是否有一个编译器指令来抑制这个警告?

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 个与此相关的警告:CS0612CS0618 - 一个用于 [Obsolete],另一个用于 [过时的(消息")].去图...

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 属性一起使用的类上使用 Obsolete 属性时如何忽略编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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