Exemple #1
0
        public static void LeaveDotsAndSlashesEscaped(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            FieldInfo fieldInfo = uri.GetType().GetField("m_Syntax", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fieldInfo == null)
            {
                throw new MissingFieldException("'m_Syntax' field not found");
            }
            object uriParser = fieldInfo.GetValue(uri);

            fieldInfo = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fieldInfo == null)
            {
                throw new MissingFieldException("'m_Flags' field not found");
            }
            object uriSyntaxFlags = fieldInfo.GetValue(uriParser);

            // Clear the flag that we don't want
            uriSyntaxFlags = (int)uriSyntaxFlags & ~UnEscapeDotsAndSlashes;

            fieldInfo.SetValue(uriParser, uriSyntaxFlags);
        }
 /// <summary>
 /// �Է��䷽ʽ������ͨ��Application��ȡ����
 /// </summary>
 /// <param name="pathUri"></param>
 /// <returns></returns>
 public static System.IO.Stream ApplicationResourceStream(Uri pathUri)
 {
     if (!supportApplication)
     {
         return null;
     }
     try
     {
         if (appType == null)
         {
             try
             {
                 appType = JavaRuntime.ClassforName("System.Windows.Application");
                 supportApplication = true;
             }
             catch
             {
                 supportApplication = false;
             }
         }
         object o = JavaRuntime.NewInstance(appType);
         System.Reflection.MethodInfo method = JavaRuntime.GetMethod(appType, "GetResourceStream", pathUri.GetType());
         object res = JavaRuntime.Invoke(method, o, pathUri);
         if (res != null)
         {
             System.Reflection.MethodInfo info = res.GetType().GetMethod("get_Stream");
             object open = JavaRuntime.Invoke(info, res);
             return open as System.IO.Stream;
         }
     }
     catch
     {
     }
     return null;
 }
        public void Complex_parameters()
        {
            var target = new Interpreter();

            var x = new MyTestService();
            var y = new Uri("http://www.google.com");
            var z = CultureInfo.GetCultureInfo("en-US");
            var parameters = new[] {
                            new Parameter("x", x.GetType(), x),
                            new Parameter("y", y.GetType(), y),
                            new Parameter("z", z.GetType(), z)
                            };

            Assert.AreEqual(x, target.Eval("x", parameters));
            Assert.AreEqual(y, target.Eval("y", parameters));
            Assert.AreEqual(z, target.Eval("z", parameters));
        }
        /// <summary>
        /// This method was copied  as-is from AmazonServiceClient.
        /// TODO When the SDK supports arrays in request parameters remove this method.
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        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
        }
        internal static CodeAccessPermission CreateUriReadPermission(Uri uri)
        {
            // explicitly disallow sub-classed Uris to guard against
            // exploits where we "lie" about some of the properties on the Uri.
            // and then later change the value returned
            //      ( e.g. supply a different uri from what checked here)
            if (uri.GetType().IsSubclassOf(typeof(Uri)))
            {
                DemandInfrastructurePermission();
            }

            if (uri.IsFile)
                return new FileIOPermission(FileIOPermissionAccess.Read, uri.LocalPath);

            // Add appropriate demands for other Uri types here.
            return null;
        }