private static void DontUnescapePathDotsAndSlashes(Uri uri)
{
#if BCL
// System.UriSyntaxFlags is internal
const int UnEscapeDotsAndSlashes = 0x2000000;
if (uri == null)
throw new ArgumentNullException("uri");
try
{
// currently prefer silent return than exceptions or log messages if reflection fails to
// find the fields we need, otherwise we could generate a lot of noise if someone
// runs on a platform without these fields
FieldInfo fieldInfo = uri.GetType().GetField("m_Syntax", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo == null)
return;
var uriParser = fieldInfo.GetValue(uri);
fieldInfo = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo == null)
return;
var uriSyntaxFlags = fieldInfo.GetValue(uriParser);
uriSyntaxFlags = (int)uriSyntaxFlags & ~UnEscapeDotsAndSlashes;
fieldInfo.SetValue(uriParser, uriSyntaxFlags);
}
catch (Exception)
{
// swallow the exception because this platform doesn't support the hack to fix the big in the Uri class.
}
#endif
}