2014-01-16 246 views
5

我想使用System.Xml.XmlReader.ReadString(),但我注意到它並未顯示在Intellisense中,因爲該功能是用[EditorBrowsable(EditorBrowsableState.Never)]修飾的。儘管沒有被標記爲[Obsolete],但我認爲微軟不希望我使用它。XmlReader.ReadString是否已被棄用或廢棄?

我在MSDN上找不到任何提及。我應該用什麼來代替?在ILSpy中,我看到ReadElementContentAsString()ReadContentAsString()。這是我想用的嗎?我正在使用.Net 4.5。

如果它是相關的,這個問題是提示您通過這樣的回答:https://stackoverflow.com/a/625463/47589

回答

3

isn't deprecated。我認爲你的推理是正確的。框架開發人員可能將其標記爲[EditorBrowsable(EditorBrowsableState.Never)],以便它不會顯示在智能感知中,並「推動」您使用更好的替代方案,可能是ReadContentAsString

根據C# In a Nutshell

ReadStringReadElementString的行爲很像0​​ 和ReadElementContentAsString,但他們拋出 Exception如果有比 元素內的文本節點多。一般而言,應避免使用這些方法,因爲如果元素包含註釋,則會拋出異常。

也許這就是爲什麼你在IL看到ReadContentAsString,因爲框架內部將所有來電ReadStringReadContentAsString和框架開發人員故意隱瞞ReadString從智能感知。

查看相關:System.ComponentModel.EditorBrowsable was written by idiots

+0

什麼是更好的選擇? – Amy

+1

給出1000分。很好的回答傢伙 –