[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));
}
}