针对无效索引的 XNodeReader.GetAttribute 行为

XNodeReader 是一个内部类,但如果通过 XmlReader 类调用 XNode.CreateReader,则可以访问该类。 除 XmlReader 之外的所有 XNodeReader 实现都对 ArgumentOutOfRangeException 方法中的无效索引引发 GetAttribute(Int32)。 通过此更改,XNodeReader.GetAttribute(int) 现在也会针对无效索引抛出 ArgumentOutOfRangeException

旧行为

XNodeReader.GetAttribute(int)如果索引无效,则返回null

新行为

XNodeReader.GetAttribute(int) 如果索引无效,则抛出ArgumentOutOfRangeException

已引入的版本

.NET 6

破坏性变更的类型

此更改可能会影响 源兼容性

更改原因

XmlReader.GetAttribute(int) 记录良好,XNodeReader 行为与记录的不一致。 无效索引的行为也与其他 XmlReader 实现不一致。

为了避免无效索引,请执行以下操作:

受影响的 API