private GetToken ( |
||
cls | ||
perm | IPermission | |
리턴 |
internal PermissionToken GetToken(Type cls, IPermission perm)
{
BCLDebug.Assert( cls != null, "Must pass in valid type" );
IntPtr typePtr = cls.TypeHandle.Value;
object tok = m_handleTable[typePtr];
if (tok == null)
{
String typeStr = cls.AssemblyQualifiedName;
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)
{
if (perm != null)
{
if (CodeAccessPermission.CanUnrestrictedOverride(perm))
tok = new PermissionToken( m_index++, PermissionTokenType.IUnrestricted, typeStr );
else
tok = new PermissionToken( m_index++, PermissionTokenType.Normal, typeStr );
}
else
{
if (cls.GetInterface(s_unrestrictedPermissionInferfaceName) != null)
tok = new PermissionToken( m_index++, PermissionTokenType.IUnrestricted, typeStr );
else
tok = new PermissionToken( m_index++, PermissionTokenType.Normal, typeStr );
}
m_tokenTable.Add(typeStr, tok);
m_indexTable.Add(m_index - 1, tok);
PermissionToken.s_tokenSet.SetItem( ((PermissionToken)tok).m_index, tok );
}
if (!m_handleTable.Contains( typePtr ))
m_handleTable.Add( typePtr, tok );
}
}
else
{
lock (this)
{
if (!m_handleTable.Contains( typePtr ))
m_handleTable.Add( typePtr, tok );
}
}
}
if ((((PermissionToken)tok).m_type & PermissionTokenType.DontKnow) != 0)
{
if (perm != null)
{
BCLDebug.Assert( !(perm is IBuiltInPermission), "This should not be called for built-ins" );
if (CodeAccessPermission.CanUnrestrictedOverride(perm))
((PermissionToken)tok).m_type = PermissionTokenType.IUnrestricted;
else
((PermissionToken)tok).m_type = PermissionTokenType.Normal;
((PermissionToken)tok).m_strTypeName = perm.GetType().AssemblyQualifiedName;
}
else
{
BCLDebug.Assert( cls.GetInterface( "System.Security.Permissions.IBuiltInPermission" ) == null, "This shoudl not be called for built-ins" );
if (cls.GetInterface(s_unrestrictedPermissionInferfaceName) != null)
((PermissionToken)tok).m_type = PermissionTokenType.IUnrestricted;
else
((PermissionToken)tok).m_type = PermissionTokenType.Normal;
((PermissionToken)tok).m_strTypeName = cls.AssemblyQualifiedName;
}
}
return (PermissionToken)tok;
}
PermissionTokenFactory::GetToken ( String typeStr ) : |
[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)); } }