问题
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
andReadElementString
behave likeReadContentAsString
andReadElementContentAsString
, except that they throw anException
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