private XmlAttributeNode GetAttributeNode(string name)
{
if (name == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(name)));
if (!_node.CanGetAttribute)
return null;
int index = name.IndexOf(':');
string prefix;
string localName;
if (index == -1)
{
if (name == xmlns)
{
prefix = xmlns;
localName = string.Empty;
}
else
{
prefix = string.Empty;
localName = name;
}
}
else
{
// If this function becomes a performance issue because of the allocated strings then we can
// make a version of Equals that takes an offset and count into the string.
prefix = name.Substring(0, index);
localName = name.Substring(index + 1);
}
XmlAttributeNode[] attributeNodes = _attributeNodes;
int attributeCount = _attributeCount;
int attributeIndex = _attributeStart;
for (int i = 0; i < attributeCount; i++)
{
if (++attributeIndex >= attributeCount)
{
attributeIndex = 0;
}
XmlAttributeNode attributeNode = attributeNodes[attributeIndex];
if (attributeNode.IsPrefixAndLocalName(prefix, localName))
{
_attributeStart = attributeIndex;
return attributeNode;
}
}
return null;
}