internal static Exception TryToUri(string s, out Uri result)
{
result = null;
if (s != null && s.Length > 0)
{ //string.Empty is a valid uri but not " "
s = TrimString(s);
if (s.Length == 0 || s.IndexOf("##", StringComparison.Ordinal) != -1)
{
return new FormatException(SR.Format(SR.XmlConvert_BadFormat, s, "Uri"));
}
}
if (!Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out result))
{
return new FormatException(SR.Format(SR.XmlConvert_BadFormat, s, "Uri"));
}
return null;
}