XmlReader.ReadString 是否已弃用或已过时? [英] Is XmlReader.ReadString deprecated or obsoleted?

查看:19
本文介绍了XmlReader.ReadString 是否已弃用或已过时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 System.Xml.XmlReader.ReadString(),但我注意到它没有出现在 Intellisense 中,因为该函数是用 [EditorBrowsable(EditorBrowsableState.从不)].尽管没有被标记为 [Obsolete],但我认为微软不希望我使用它.

我在 MSDN 上找不到任何提及.我应该用什么代替?在 ILSpy 中,我看到 ReadElementContentAsString()ReadContentAsString().这是我想用的吗?我使用的是 .Net 4.5.

如果相关,这个问题是由这个答案提示的:https://stackoverflow.com/a/625463/47589

解决方案

It 未弃用.我认为你的推理是正确的.框架开发人员可能将其标记为 [EditorBrowsable(EditorBrowsableState.Never)] 以便它不会出现在智能感知中,并推动"您使用更好的替代方案,这可能是 ReadContentAsString.

根据 Inpage&q">><块引用>

ReadStringReadElementString 的行为类似于 ReadContentAsStringReadElementContentAsString,除了它们抛出一个Exception 如果有多个单个文本节点元素.通常,应避免使用这些方法,因为它们会抛出如果元素包含注释,则异常.

也许这就是您在 IL 中看到 ReadContentAsString 的原因,因为框架在内部将所有对 ReadString 的调用转换为 ReadContentAsString 和框架开发人员有意将 ReadString 从智能感知中隐藏起来.

见相关:System.ComponentModel.EditorBrowsable 是白痴写的

I'm wanting to use System.Xml.XmlReader.ReadString(), but I noticed it doesn't show up in Intellisense because the function is decorated with [EditorBrowsable(EditorBrowsableState.Never)]. Despite not being marked as [Obsolete], I assume Microsoft doesn't want me to use it.

I can't find any mention of this on MSDN. What should I be using instead? In ILSpy I see ReadElementContentAsString() and ReadContentAsString(). Is this what I want to use instead? I am using .Net 4.5.

In case it's relevant, this question was prompted by this answer: https://stackoverflow.com/a/625463/47589

解决方案

It isn't deprecated. I think your reasoning is correct. The framework developers likely marked it as [EditorBrowsable(EditorBrowsableState.Never)] so that it doesn't show up in intellisense, and "nudges" you to use a better alternative, which maybe ReadContentAsString.

According to C# In a Nutshell.

ReadString and ReadElementString behave like ReadContentAsString and ReadElementContentAsString, except that they throw an Exception if there's more than a single text node within the element. In general, these methods should be avoided, as they throw an exception if an element contains a comment.

Maybe that's why you are seeing ReadContentAsString in the IL, because the framework is internally converting all calls to ReadString to ReadContentAsString and the Framework developers intentionally hid ReadString from the intellisense.

See related : System.ComponentModel.EditorBrowsable was written by idiots

这篇关于XmlReader.ReadString 是否已弃用或已过时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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