c# - 过时的意思

标签 c# c++ .net visual-studio-2010 obsolete

我接手了一个包含大量遗留代码的项目,包括 C++ 和 C#,目前在 VS 2010(在 Windows 7 上)下编译。

当我构建解决方案时,令人惊讶的是,成功构建了 143 个项目。然而,有一大堆警告。其中数量惊人的警告功能已过时。

warning CS0618: 'System.Runtime.InteropServices.UCOMIMoniker' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIEnumMoniker' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIRunningObjectTable' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIRunningObjectTable' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIBindCtx' is obsolete
warning CS0618: 'System.IO.Path.InvalidPathChars' is obsolete
warning CS0618: 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete
warning CS0618: 'System.Net.Dns.GetHostByName(string)' is obsolete

这是什么意思?这些函数显然仍然被定义,否则它们将无法编译或给我某种“未找到”或“未定义”的错误。是否缺少实现?这些功能是否仍然有效(和以前一样)?

有几个我查过,它们已经过时很久了。例如,GetHostByName:

.NET 框架

Supported in: 1.1
Obsolete (compiler warning) in 4.6
Obsolete (compiler warning) in 4.6
Obsolete (compiler warning) in 4.5
Obsolete (compiler warning) in 4.5.1
Obsolete (compiler warning) in 4.5.2
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

如果我没理解错的话,它在过去 8-9 年里已经过时了(.NET 2.0 于 2006 年推出)。为什么没有人修复这些?他们需要修理吗?当我研究 GetHostByName 方法时,它被 GetHostEntry 取代了。很简单...但是等一下,有很多人提示它与新功能的工作方式不一样,也许您应该用对 GetHostAddresses 的调用来代替它。好吧,该死。

考虑到我的解决方案中有超过 28k 个文件,我不确定我是否可以随便乱搞这些东西。有没有办法知道过时的功能将支持多长时间?我是否应该期望这些在我安装系统后还能工作?让代码调用过时接口(interface) (MSDN) 对系统有何影响?

我并不是想了解如何从我自己的系统中删除过时的代码,而是系统应该如何处理外部系统(例如 MSDN)上过时的接口(interface)。他们显然没有遵循标记过时、替换和删除旧接口(interface)的简单循环。他们的政策是什么? MSDN 定义的接口(interface)的用户应该如何对过时的标记使用react,特别是当过时的代码没有被“同类”等效功能替换时。

最佳答案

类或方法通常会被标记为过时,因为它们将在下一个版本中被弃用,或者不再是执行特定任务的最有效方法。但是,Microsoft 经常将这些方法保留很长时间以保证向后兼容性。

关于c# - 过时的意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29781018/

相关文章:

c# - 在 Windows Phone 7.5 Mango 中实现闹钟

c++ - 在不停止程序的情况下在 C++ 中获取用户输入

C++ 类型转换 int 到 union

c# - 解析 XML 内容 - C#

c# - 拒绝从 ASP.NET 网站启动进程

c++ - 使用相同的键高效地迭代多个映射

c# - 为什么我的自定义用户控件的子控件没有被初始化?

.net - 如何绑定(bind)到 ToolStripMenuItem 的 Enabled 属性

C# -> 从 SQL Server 2008 检索数据集

c# - 如何从后台 worker 将文本设置为 TextBlock