System.Security.PermissionTokenFactory.GetToken C# (CSharp) Method

GetToken() private method

private GetToken ( String typeStr ) : PermissionToken
typeStr String
return PermissionToken
        internal PermissionToken GetToken(String typeStr)
        {
            Object tok = null;
            tok = m_tokenTable != null ? m_tokenTable[typeStr] : null; // Assumes asynchronous lookups are safe
            if (tok == null)
            {
                lock (this)
                {
                    if (m_tokenTable != null)
                        tok = m_tokenTable[typeStr]; // Make sure it wasn't just added
                    else
                        m_tokenTable = new Hashtable( m_size, 1.0f, new PermissionTokenKeyComparer( CultureInfo.InvariantCulture ) );
                        
                    if (tok == null)
                    {
                        tok = new PermissionToken( m_index++, PermissionTokenType.DontKnow, typeStr );
                        m_tokenTable.Add(typeStr, tok);
                        m_indexTable.Add(m_index - 1, tok);
                        PermissionToken.s_tokenSet.SetItem( ((PermissionToken)tok).m_index, tok );
                    }
                }
            }

            return (PermissionToken)tok;
        }

Same methods

PermissionTokenFactory::GetToken ( Type cls, IPermission perm ) : PermissionToken

Usage Example

Example #1
0
        [System.Security.SecurityCritical]  // auto-generated
        public static PermissionToken GetToken(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.GetToken(cls, null));
            }
        }
All Usage Examples Of System.Security.PermissionTokenFactory::GetToken