internal static XName ToXName(this string self, XmlReader reader)
{
var i = self.IndexOf(':');
if (i == 0 || i == self.Length - 1)
{
throw new XmlException($"\"{self}\" is not QName.");
}
var prefix = string.Empty;
var localPart = string.Empty;
if (i < 0)
{
localPart = self;
}
else
{
prefix = self.Substring(0, i);
localPart = self.Substring(i + 1);
}
XNamespace ns = reader.LookupNamespace(prefix);
if (ns == null)
{
throw new XmlException($"The prefix \"{prefix}\" is not declared.");
}
return ns + localPart;
}