FindToken() private method

private FindToken ( Type cls ) : PermissionToken
cls System.Type
return PermissionToken
Ejemplo n.º 1
0
        public static PermissionToken FindToken(Type cls)
        {
            if (cls == null)
            {
                return(null);
            }

#if FEATURE_CAS_POLICY
            if (cls.GetInterface("System.Security.Permissions.IBuiltInPermission") != null)
            {
                if (s_reflectPerm == null)
                {
                    s_reflectPerm = new ReflectionPermission(PermissionState.Unrestricted);
                }
                s_reflectPerm.Assert();
                MethodInfo method = cls.GetMethod("GetTokenIndex", BindingFlags.Static | BindingFlags.NonPublic);
                Contract.Assert(method != null, "IBuiltInPermission types should have a static method called 'GetTokenIndex'");

                // GetTokenIndex needs to be invoked without any security checks, since doing a security check
                // will involve a ReflectionTargetDemand which creates a CompressedStack and attempts to get the
                // token.
                RuntimeMethodInfo getTokenIndex = method as RuntimeMethodInfo;
                Contract.Assert(getTokenIndex != null, "method is not a RuntimeMethodInfo");
                int token = (int)getTokenIndex.UnsafeInvoke(null, BindingFlags.Default, null, null, null);
                return(s_theTokenFactory.BuiltInGetToken(token, null, cls));
            }
            else
#endif // FEATURE_CAS_POLICY
            {
                return(s_theTokenFactory.FindToken(cls));
            }
        }
Ejemplo n.º 2
0
        public static PermissionToken FindToken(Type cls)
        {
            if (cls == null)
            {
                return(null);
            }
            if (cls.GetInterface("System.Security.Permissions.IBuiltInPermission") == null)
            {
                return(s_theTokenFactory.FindToken(cls));
            }
            if (s_reflectPerm == null)
            {
                s_reflectPerm = new ReflectionPermission(PermissionState.Unrestricted);
            }
            s_reflectPerm.Assert();
            RuntimeMethodInfo method = cls.GetMethod("GetTokenIndex", BindingFlags.NonPublic | BindingFlags.Static) as RuntimeMethodInfo;
            int index = (int)method.Invoke(null, BindingFlags.Default, null, null, null, true);

            return(s_theTokenFactory.BuiltInGetToken(index, null, cls));
        }
Ejemplo n.º 3
0
        public static PermissionToken FindToken(Type cls)
        {
            if (cls == null)
            {
                return(null);
            }

            if (cls.GetInterface("System.Security.Permissions.IBuiltInPermission") != null)
            {
                if (s_reflectPerm == null)
                {
                    s_reflectPerm = new ReflectionPermission(PermissionState.Unrestricted);
                }
                s_reflectPerm.Assert();
                MethodInfo method = cls.GetMethod("GetTokenIndex", BindingFlags.Static | BindingFlags.NonPublic);
                BCLDebug.Assert(method != null, "IBuiltInPermission types should have a static method called 'GetTokenIndex'");
                return(s_theTokenFactory.BuiltInGetToken((int)method.Invoke(null, null), null, cls));
            }
            else
            {
                return(s_theTokenFactory.FindToken(cls));
            }
        }