System.Security.CodeAccessSecurityEngine.Assert C# (CSharp) Method

Assert() static private method

static private Assert ( CodeAccessPermission cap, System.Threading.StackCrawlMark &stackMark ) : void
cap CodeAccessPermission
stackMark System.Threading.StackCrawlMark
return void
        internal static void Assert(CodeAccessPermission cap, ref StackCrawlMark stackMark)
        {
            // Make sure the caller of assert has the permission to assert
            //WARNING: The placement of the call here is just right to check
            //         the appropriate frame.
            
            // Note: if the "AssertPermission" is not a permission that implements IUnrestrictedPermission
            // you need to change the last parameter to a zero.
            BCLDebug.Assert(AssertPermissionToken != null && AssertPermission != null, "Assert Permission not setup correctly");
            FrameSecurityDescriptor secObj = CheckNReturnSO(AssertPermissionToken,
                                                            AssertPermission,
                                                            ref stackMark,
                                                            1,
                                                            1 );
            if (secObj == null)
            {
                if (SecurityManager._IsSecurityOn())
                    // Security: REQ_SQ flag is missing. Bad compiler ?
                    // This can happen when you create delegates over functions that need the REQ_SQ 
                    throw new ExecutionEngineException( Environment.GetResourceString( "ExecutionEngine_MissingSecurityDescriptor" ) );
            }
            else
            {
                if (secObj.HasImperativeAsserts())
                    throw new SecurityException( Environment.GetResourceString( "Security_MustRevertOverride" ) );

                secObj.SetAssert(cap);
            }
        }

Usage Example

        public void Assert()
        {
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;

            CodeAccessSecurityEngine.Assert(this, ref stackMark);
        }