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

GetToken() public static method

public static GetToken ( String typeStr, bool bCreateMscorlib ) : PermissionToken
typeStr String
bCreateMscorlib bool
return PermissionToken
        public static PermissionToken GetToken(String typeStr, bool bCreateMscorlib)
        {
            if (typeStr == null)
                return null;

            if (IsMscorlibClassName( typeStr ))
            {
                if (!bCreateMscorlib)
                {
                    return null;
                }
                else
                {
                    return FindToken( Type.GetType( typeStr ) );
                }
            }
            else
            {
                PermissionToken token = s_theTokenFactory.GetToken(typeStr);
#if _DEBUG
                new PermissionSet(PermissionState.Unrestricted).Assert();
                StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
                Type type = RuntimeType.PrivateGetType( typeStr.Trim().Replace( '\'', '\"' ),
                                                false,
                                                false, ref stackMark);
                BCLDebug.Assert( (type == null) || (type.Module.Assembly != System.Reflection.Assembly.GetExecutingAssembly()) || (typeStr.IndexOf("mscorlib", StringComparison.Ordinal) < 0),
                    "We should not go through this path for mscorlib based permissions" );
#endif
                return token;
            }
        }

Same methods

PermissionToken::GetToken ( IPermission perm ) : PermissionToken
PermissionToken::GetToken ( String typeStr ) : PermissionToken
PermissionToken::GetToken ( Type cls ) : PermissionToken

Usage Example

        // static default constructor. This will be called before any of the static members are accessed.
        static CodeAccessSecurityEngine()
        {
#pragma warning disable 618
            AssertPermission = new SecurityPermission(SecurityPermissionFlag.Assertion);
#pragma warning restore 618
            AssertPermissionToken = PermissionToken.GetToken(AssertPermission);
        }
All Usage Examples Of System.Security.PermissionToken::GetToken