XmlReader.ReadString是否已弃用或已过时?

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

我在MSDN上找不到这个。 我该怎么用呢? 在ILSpy中,我看到ReadElementContentAsString()ReadContentAsString() 。 这是我想要使用的吗? 我正在使用.Net 4.5。

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

它不会被弃用 。 我认为你的推理是正确的。 框架开发人员可能将其标记为[EditorBrowsable(EditorBrowsableState.Never)]以便它不会显示在intellisense中,并“轻推”您使用更好的替代方法,可能是ReadContentAsString

根据C#In a Nutshell 。

ReadStringReadElementString行为类似于ReadContentAsStringReadElementContentAsString ,除非它们在元素中有多个文本节点时抛出Exception 。 通常,应避免使用这些方法,因为如果元素包含注释,它们会抛出exception。

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

请参阅相关内容: System.ComponentModel.EditorBrowsable由idiots编写