Is XmlReader.ReadString deprecated or obsoleted?

╄→гoц情女王★ 提交于 2019-12-23 09:30:00

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/21174168/is-xmlreader-readstring-deprecated-or-obsoleted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!