Export (0) Print
Expand All

SecurityPermission Class

Describes a set of security permissions applied to code. This class cannot be inherited.

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class SecurityPermission
	Inherits CodeAccessPermission
	Implements IUnrestrictedPermission
'Usage
Dim instance As SecurityPermission

/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class SecurityPermission extends CodeAccessPermission implements IUnrestrictedPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class SecurityPermission extends CodeAccessPermission implements IUnrestrictedPermission

This permission uses the SecurityPermissionFlag enumeration. The values for this enumeration can be found in its documentation.

The following code example demonstrates the behavior of the SecurityPermission class methods. The example is intended to show the results of the methods, not to show how the methods are typically used. For an example showing the use of the SecurityPermission class to demand permission for a specific SecurityPermissionFlag enumeration value, see the SecurityPermission(SecurityPermissionFlag) constructor.

Imports System
Imports System.Security
Imports System.Security.Permissions
Imports Microsoft.VisualBasic

<Assembly: CLSCompliant(True)> 

Public Class SecurityPermissionDemo

    ' IsSubsetOf determines whether the current permission is a subset of the specified permission.
    Private Function IsSubsetOfDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim Security1, Security2 As SecurityPermissionFlag
        Dim SecurityPerm1, SecurityPerm2 As SecurityPermission
        Dim SecurityGen1 As New SecurityGenerator()
        Dim SecurityGen2 As New SecurityGenerator()
        SecurityGen1.ResetIndex()
        While SecurityGen1.GetSecurityFlag(Security1)
            SecurityPerm1 = New SecurityPermission(Security1)
            SecurityGen2.ResetIndex()
            Console.WriteLine("********************************************************" & ControlChars.Lf)

            While SecurityGen2.GetSecurityFlag(Security2)
                SecurityPerm2 = New SecurityPermission(Security2)
                Try
                    If SecurityPerm1.IsSubsetOf(SecurityPerm2) Then
                        Console.WriteLine((SecurityPerm1.Flags.ToString().ToString() _
                        & " is a subset of " & SecurityPerm2.Flags.ToString()))
                    Else
                        Console.WriteLine((SecurityPerm1.Flags.ToString() & " is not a subset of " _
                        & SecurityPerm2.Flags.ToString()))
                    End If
                Catch e As Exception
                    Console.WriteLine(("An exception was thrown for subset :" & SecurityPerm1.ToString() _
                    & ControlChars.Lf & SecurityPerm2.ToString() & ControlChars.Lf & e.ToString()))
                    returnValue = False
                End Try
ContinueWhile2:
            End While
ContinueWhile1:
        End While
        Return returnValue
    End Function 'IsSubsetOfDemo

    ' Union creates a new permission that is the union of the current permission and 
    ' the specified permission.
    Private Function UnionDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim Security1, Security2 As SecurityPermissionFlag
        Dim SecurityPerm1, SecurityPerm2 As SecurityPermission
        Dim SecurityPerm3 As IPermission
        Dim SecurityGen1 As New SecurityGenerator()
        Dim SecurityGen2 As New SecurityGenerator()
        SecurityGen1.ResetIndex()
        While SecurityGen1.GetSecurityFlag(Security1)
            SecurityPerm1 = New SecurityPermission(Security1)
            Console.WriteLine("**********************************************************" & ControlChars.Lf)
            SecurityGen2.ResetIndex()

            While SecurityGen2.GetSecurityFlag(Security2)
                SecurityPerm2 = New SecurityPermission(Security2)
                SecurityPerm3 = CType(SecurityPerm1.Union(SecurityPerm2), SecurityPermission)
                SecurityPerm3 = SecurityPerm1.Union(SecurityPerm2)

                If SecurityPerm3 Is Nothing Then
                    Console.WriteLine(("The union of " & Security1 & " and " & Security2 & " is null."))
                Else
                    Console.WriteLine(("The union of " & SecurityPerm1.Flags.ToString() _
                    & " and " & SecurityPerm2.Flags.ToString() & " = " & CType(SecurityPerm3, SecurityPermission).Flags.ToString().ToString()))
                End If
ContinueWhile2:
            End While
ContinueWhile1:
        End While


        Return returnValue
    End Function 'UnionDemo

    ' Intersect creates and returns a new permission that is the intersection of the current 
    ' permission and the permission specified.
    Private Function IntersectDemo() As Boolean
        Dim returnValue As Boolean = True
        Dim Security1, Security2 As SecurityPermissionFlag
        Dim SecurityPerm1, SecurityPerm2, SecurityPerm3 As SecurityPermission
        Dim SecurityGen1 As New SecurityGenerator()
        Dim SecurityGen2 As New SecurityGenerator()
        SecurityGen1.ResetIndex()
        While SecurityGen1.GetSecurityFlag(Security1)
            SecurityPerm1 = New SecurityPermission(Security1)
            Console.WriteLine("**********************************************************" & ControlChars.Lf)
            SecurityGen2.ResetIndex()

            While SecurityGen2.GetSecurityFlag(Security2)
                SecurityPerm2 = New SecurityPermission(Security2)
                SecurityPerm3 = CType(SecurityPerm1.Intersect(SecurityPerm2), SecurityPermission)
                If Not (SecurityPerm3 Is Nothing) Then
                    Console.WriteLine(("The intersection of " & Security1.ToString() & " and " _
                    & Security2.ToString() & " = " _
                    & CType(SecurityPerm3, SecurityPermission).Flags.ToString().ToString()))
                Else
                    Console.WriteLine(("The intersection of " & Security1.ToString() & " and " _
                    & Security2.ToString() & " is null."))
                End If
ContinueWhile2:
            End While
ContinueWhile1:
        End While

        Return returnValue
    End Function 'IntersectDemo

    'Copy creates and returns an identical copy of the current permission.
    Private Function CopyDemo() As Boolean

        Dim returnValue As Boolean = True

        Dim Security1 As SecurityPermissionFlag
        Dim SecurityPerm1, SecurityPerm2 As SecurityPermission

        Dim SecurityGen1 As New SecurityGenerator()
        Dim SecurityGen2 As New SecurityGenerator()

        SecurityGen1.ResetIndex()
        While SecurityGen1.GetSecurityFlag(Security1)
            SecurityPerm1 = New SecurityPermission(Security1)
            SecurityGen2.ResetIndex()
            Console.WriteLine("********************************************************" & ControlChars.Lf)
            Try
                SecurityPerm2 = CType(SecurityPerm1.Copy(), SecurityPermission)
                Console.WriteLine(("Result of copy = " & SecurityPerm2.ToString()))

            Catch e As Exception
                Console.WriteLine(("Copy failed :" & SecurityPerm1.ToString() & e.ToString()))
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While
        Return returnValue
    End Function 'CopyDemo

    ' ToXml creates an XML encoding of the permission and its current state; 
    ' FromXml reconstructs a permission with the specified state from the XML encoding. 
    Private Function ToFromXmlDemo() As Boolean

        Dim returnValue As Boolean = True

        Dim Security1 As SecurityPermissionFlag
        Dim SecurityPerm1, SecurityPerm2 As SecurityPermission
        Dim SecurityGen1 As New SecurityGenerator()
        Dim SecurityGen2 As New SecurityGenerator()
        SecurityGen1.ResetIndex()
        While SecurityGen1.GetSecurityFlag(Security1)
            SecurityPerm1 = New SecurityPermission(Security1)
            Console.WriteLine("********************************************************" & ControlChars.Lf)
            SecurityGen2.ResetIndex()
            Try
                SecurityPerm2 = New SecurityPermission(PermissionState.None)
                SecurityPerm2.FromXml(SecurityPerm1.ToXml())
                Console.WriteLine(("Result of ToFromXml = " & SecurityPerm2.ToString()))

            Catch e As Exception
                Console.WriteLine(("ToFromXml failed :" & SecurityPerm1.ToString() & e.ToString()))
                GoTo ContinueWhile1
            End Try
ContinueWhile1:
        End While

        Return returnValue
    End Function 'ToFromXmlDemo

    ' Invoke all demos.
    Public Function runDemo() As Boolean
        Dim returnCode As Boolean = True
        Dim tempReturnCode As Boolean

        ' Call the IsSubsetOf demo.
        tempReturnCode = IsSubsetOfDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("IsSubsetOf demo completed successfully.")
        Else
            Console.Out.WriteLine("IsSubsetOf demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the Union demo.
        tempReturnCode = UnionDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("Union demo completed successfully.")
        Else
            Console.Out.WriteLine("Union demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the Intersect demo.	
        tempReturnCode = IntersectDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("Intersect demo completed successfully.")
        Else
            Console.Out.WriteLine("Intersect demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode


        ' Call the Copy demo.	
        tempReturnCode = CopyDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("Copy demo completed successfully.")
        Else
            Console.Out.WriteLine("Copy demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        ' Call the ToFromXml demo.	
        tempReturnCode = ToFromXmlDemo()
        If tempReturnCode Then
            Console.Out.WriteLine("ToFromXml demo completed successfully.")
        Else
            Console.Out.WriteLine("ToFromXml demo failed.")
        End If
        returnCode = tempReturnCode AndAlso returnCode

        Return returnCode
    End Function 'runDemo

    ' Test harness.
    Public Overloads Shared Sub Main(ByVal args() As [String])
        Try
            Dim democase As New SecurityPermissionDemo()
            Dim returnCode As Boolean = democase.runDemo()
            If returnCode Then
                Console.Out.WriteLine("SecurityPermission demo completed successfully.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 100
            Else
                Console.Out.WriteLine("SecurityPermission demo failed.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 101
            End If
        Catch e As Exception
            Console.Out.WriteLine("SecurityPermission demo failed.")
            Console.WriteLine(e.ToString())
            Console.Out.WriteLine("Press the Enter key to exit.")
            Dim consoleInput As String = Console.ReadLine()
            System.Environment.ExitCode = 101
        End Try
    End Sub 'Main
End Class 'SecurityPermissionDemo


' This class generates SecurityPermission objects.

Friend Class SecurityGenerator


    Private mySecurity As SecurityPermissionFlag() = {SecurityPermissionFlag.AllFlags, _
    SecurityPermissionFlag.Assertion Or SecurityPermissionFlag.ControlAppDomain, _
    SecurityPermissionFlag.ControlAppDomain, _
    SecurityPermissionFlag.ControlDomainPolicy Or SecurityPermissionFlag.ControlEvidence, _
    SecurityPermissionFlag.ControlEvidence, _
    SecurityPermissionFlag.ControlPolicy Or SecurityPermissionFlag.ControlPrincipal, _
    SecurityPermissionFlag.ControlPrincipal, _
    SecurityPermissionFlag.ControlThread, _
    SecurityPermissionFlag.Execution, _
    SecurityPermissionFlag.Infrastructure, _
    SecurityPermissionFlag.NoFlags, _
    SecurityPermissionFlag.RemotingConfiguration Or SecurityPermissionFlag.SerializationFormatter, _
    SecurityPermissionFlag.SerializationFormatter, _
    SecurityPermissionFlag.SkipVerification, _
    SecurityPermissionFlag.UnmanagedCode}

    Private reflectionIndex As Integer = 0


    Public Sub New()
        ResetIndex()
    End Sub 'New


    Public Sub ResetIndex()
        reflectionIndex = 0
    End Sub 'ResetIndex

    ' GetSecurityFlag creates a SecurityPermission object.
    Public Function GetSecurityFlag(ByRef Security As SecurityPermissionFlag) As Boolean

        If reflectionIndex >= mySecurity.Length Then

            Security = SecurityPermissionFlag.NoFlags
            reflectionIndex &= 1
            Return False
        End If
        Security = mySecurity(reflectionIndex)
        reflectionIndex = reflectionIndex + 1
        Return True
    End Function

import System.*;
import System.Security.*;
import System.Security.Permissions.*;

/** @assembly CLSCompliant(true)
 */

public class SecurityPermissionDemo
{
    // IsSubsetOf determines whether the current permission is a 
    // subset of the specified permission.
    private boolean IsSubsetOfDemo() 
    {
        boolean returnValue = true;
        SecurityPermissionFlag security1[] = new SecurityPermissionFlag[1];
        SecurityPermissionFlag security2[] = new SecurityPermissionFlag[1];
        SecurityPermission securityPerm1[] = new SecurityPermission[1];
        SecurityPermission securityPerm2[] = new SecurityPermission[1];
        SecurityGenerator securityGen1 = new SecurityGenerator();
        SecurityGenerator securityGen2 = new SecurityGenerator();
        securityGen1.ResetIndex();
        
        while (securityGen1.CreateSecurity(securityPerm1, security1)) {
            if (securityPerm1[0] == null) {
                continue ;
            }
            securityGen2.ResetIndex();
            Console.WriteLine("****************************" 
                + "****************************\n");
            
            while (securityGen2.CreateSecurity(securityPerm2, security2)) {
                if (securityPerm2[0] == null) {
                    continue ;
                }
                try {
                    if (securityPerm1[0].IsSubsetOf(securityPerm2[0])) {
                        Console.WriteLine((securityPerm1[0].get_Flags() 
                            + " is a subset of " 
                            + securityPerm2[0].get_Flags()));
                    }
                    else {
                        Console.WriteLine((securityPerm1[0].get_Flags() 
                            + " is not a subset of " 
                            + securityPerm2[0].get_Flags()));
                    }
                }
                catch(System.Exception e) { 
                    Console.WriteLine(("An exception was " 
                        + "thrown for subset :" + securityPerm1[0] 
                        + "\n" + securityPerm2[0] + "\n" + e));
                    returnValue = false;
                }
            }
        }
        return returnValue ;
    } //IsSubsetOfDemo

    // Union creates a new permission that is the union of the 
    // current permission and the specified permission.
    private boolean UnionDemo() 
    {
        boolean returnValue = true;
        SecurityPermissionFlag security1[] = new SecurityPermissionFlag[1];
        SecurityPermissionFlag security2[] = new SecurityPermissionFlag[1];
        SecurityPermission securityPerm1[] = new SecurityPermission[1];
        SecurityPermission securityPerm2[] = new SecurityPermission[1];
        IPermission securityPerm3;
        SecurityGenerator securityGen1 = new SecurityGenerator();
        SecurityGenerator securityGen2 = new SecurityGenerator();
        securityGen1.ResetIndex();

        while (securityGen1.CreateSecurity(securityPerm1, security1)) {
            if (securityPerm1[0] == null) {
                continue ;
            }
            Console.WriteLine("*******************************" 
                + "***************************\n");
            securityGen2.ResetIndex();
            
            while (securityGen2.CreateSecurity(securityPerm2, security2)) {
                if (securityPerm2[0] == null) {
                    continue ;
                }
                securityPerm3 =((SecurityPermission)(securityPerm1[0].
                    Union(securityPerm2[0])));
                securityPerm3 = securityPerm1[0].Union(securityPerm2[0]);
                
                if (securityPerm3 == null) {
                    Console.WriteLine(("The union of "     + security1[0] 
                    + " and " + security2[0] + " is null."));
                }
                else {
                    Console.WriteLine(("The union of " 
                        + securityPerm1[0].get_Flags() 
                        + " and " + securityPerm2[0].get_Flags() + " = " 
                        + ((SecurityPermission)(securityPerm3)).
                        get_Flags().ToString()));
                }
            }
        }return returnValue ;
    } //UnionDemo    

    // Intersect creates and returns a new permission that is the 
    // intersection of the current
    // permission and the permission specified.
    private boolean IntersectDemo() 
    {
        boolean returnValue = true;
        SecurityPermissionFlag security1[] = new SecurityPermissionFlag[1];
        SecurityPermissionFlag security2[] = new SecurityPermissionFlag[1];
        SecurityPermission securityPerm1[] = new SecurityPermission[1];
        SecurityPermission securityPerm2[] = new SecurityPermission[1];
        SecurityPermission securityPerm3;
        SecurityGenerator securityGen1 =  new SecurityGenerator();
        SecurityGenerator securityGen2 =  new SecurityGenerator();
        securityGen1.ResetIndex();
        while (securityGen1.CreateSecurity(securityPerm1, security1)) {
            if (securityPerm1[0] == null) {
                continue ;
            }
            Console.WriteLine("********************************" 
                + "**************************\n");
            securityGen2.ResetIndex();
            
            while (securityGen2.CreateSecurity(securityPerm2, security2)) {
                if (securityPerm2[0] == null) {
                    continue ;
                }
                
                securityPerm3 =((SecurityPermission)(
                securityPerm1[0].Intersect(securityPerm2[0])));
                if (securityPerm3 != null) {
                    Console.WriteLine(("The intersection of " 
                        + security1[0] + " and " + security2[0] + " = " 
                        + ((SecurityPermission)(securityPerm3)).
                        get_Flags().ToString()));
                }
                else {
                    Console.WriteLine(("The intersection of " 
                        + security1[0] + " and " + security2[0] + " is null."));
                }
            }
        }      
        return returnValue ;
    } //IntersectDemo

    //Copy creates and returns an identical copy of the current permission.
    private boolean CopyDemo() 
    {
        boolean returnValue = true;
        
        SecurityPermissionFlag security1[] = new SecurityPermissionFlag[1];
        SecurityPermission securityPerm1[] = new SecurityPermission[1];
        SecurityPermission securityPerm2[] = new SecurityPermission[1];
        
        SecurityGenerator securityGen1 =  new SecurityGenerator();
        SecurityGenerator securityGen2 =  new SecurityGenerator();
        
        securityGen1.ResetIndex();
        while (securityGen1.CreateSecurity(securityPerm1, security1)) {
            if (securityPerm1[0] == null) {
                continue ;
            }
            securityGen2.ResetIndex();
            Console.WriteLine("***************************************" 
                + "*****************\n");
            try {
                securityPerm2[0] =((SecurityPermission)(
                    securityPerm1[0].Copy()));
                Console.WriteLine(("Result of copy = " 
                    + securityPerm2[0].ToString()));
            } 
            catch(System.Exception e) {
                Console.WriteLine(("Copy failed :" 
                    + securityPerm1[0].ToString() + e));
                continue ;
            }
        }
        return returnValue ;
    } //CopyDemo

    // ToXml creates an XML encoding of the permission and its current state;
    // FromXml reconstructs a permission with the specified state 
    // from the XML encoding.
    private boolean ToFromXmlDemo() 
    {
        boolean returnValue = true;
           SecurityPermissionFlag security1[] = new SecurityPermissionFlag[1];
        SecurityPermission securityPerm1[] = new SecurityPermission[1];
        SecurityPermission securityPerm2[] = new SecurityPermission[1];
        SecurityGenerator securityGen1 =  new SecurityGenerator();
        SecurityGenerator securityGen2 =  new SecurityGenerator();
        securityGen1.ResetIndex();
        while (securityGen1.CreateSecurity(securityPerm1, security1)) {
            if (securityPerm1[0] == null) {
                continue ;
            }
            Console.WriteLine("*****************************" 
                + "***************************\n");
            securityGen2.ResetIndex();
            try {
                securityPerm2[0] = 
                    new SecurityPermission(PermissionState.None);
                securityPerm2[0].FromXml(securityPerm1[0].ToXml());
                Console.WriteLine(("Result of ToFromXml = " 
                    + securityPerm2[0].ToString()));
            }        
            catch(System.Exception e) {
                Console.WriteLine(("ToFromXml failed :" 
                    + securityPerm1[0].ToString() + e));
                continue ;
            }
        }      
        return returnValue ;
    } //ToFromXmlDemo

    // Invoke all demos.
    public boolean runDemo() 
    {
        boolean returnCode = true;
        boolean tempReturnCode;
        
        // Call the IsSubsetOf demo.
        tempReturnCode = IsSubsetOfDemo();
        if (tempReturnCode) {
            Console.get_Out().WriteLine("IsSubsetOf demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("IsSubsetOf demo failed.");
        }
        returnCode = tempReturnCode && returnCode;
        
        // Call the Union demo.
        tempReturnCode = UnionDemo();
        if (tempReturnCode) {
            Console.get_Out().WriteLine("Union demo completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Union demo failed.");
        }
        returnCode = tempReturnCode && returnCode;
        
        // Call the Intersect demo.
        tempReturnCode = IntersectDemo();
        if (tempReturnCode) {
            Console.get_Out().WriteLine("Intersect demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Intersect demo failed.");
        }
        returnCode = tempReturnCode && returnCode;
        
        
        // Call the Copy demo.
        tempReturnCode = CopyDemo();
        if (tempReturnCode) {
            Console.get_Out().WriteLine("Copy demo completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Copy demo failed.");
        }
        returnCode = tempReturnCode && returnCode;
        
        // Call the ToFromXml demo.
        tempReturnCode = ToFromXmlDemo();
        if (tempReturnCode) {
            Console.get_Out().WriteLine("ToFromXml demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("ToFromXml demo failed.");
        }
        returnCode = tempReturnCode && returnCode;      
        return returnCode ;
    } //runDemo

    // Test harness.
    public static void main(String[] args)
    {
        try {
            SecurityPermissionDemo democase =  new SecurityPermissionDemo();
            boolean returnCode = democase.runDemo();
            if (returnCode) {
                Console.get_Out().WriteLine("SecurityPermission demo " 
                    + "completed successfully.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                System.Environment.set_ExitCode(100);
            }
            else {
                Console.get_Out().WriteLine("SecurityPermission demo failed.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                System.Environment.set_ExitCode(101);
            }
        }
        catch (System.Exception e) {
              Console.get_Out().WriteLine("SecurityPermission demo failed.");
            Console.WriteLine(e.ToString());
            Console.get_Out().WriteLine("Press the Enter key to exit.");
            String consoleInput = Console.ReadLine();
            System.Environment.set_ExitCode(101);
        }
    } //main
} //SecurityPermissionDemo

// This class generates SecurityPermission objects.
class SecurityGenerator
{
    private SecurityPermissionFlag mySecurity[] =  
        {
        SecurityPermissionFlag.AllFlags, 
        SecurityPermissionFlag.Assertion, 
        SecurityPermissionFlag.ControlAppDomain, 
        SecurityPermissionFlag.ControlDomainPolicy, 
        SecurityPermissionFlag.ControlEvidence, 
        SecurityPermissionFlag.ControlPolicy, 
        SecurityPermissionFlag.ControlPrincipal, 
        SecurityPermissionFlag.ControlThread, 
        SecurityPermissionFlag.Execution, 
        SecurityPermissionFlag.Infrastructure, 
        SecurityPermissionFlag.NoFlags, 
        SecurityPermissionFlag.RemotingConfiguration, 
        SecurityPermissionFlag.SerializationFormatter, 
        SecurityPermissionFlag.SkipVerification, 
        SecurityPermissionFlag.UnmanagedCode
        };   
    
    private int reflectionIndex = 0;   

    public SecurityGenerator() 
    {
        ResetIndex();
    } //SecurityGenerator

    public void ResetIndex() 
    {
        reflectionIndex = 0;
    } //ResetIndex

    // CreateSecurity creates a SecurityPermission object.
    public boolean CreateSecurity(
        SecurityPermission securityPerm[], SecurityPermissionFlag security[]) 
    {
        if (reflectionIndex >= mySecurity.length) {
            securityPerm[0] = new SecurityPermission(PermissionState.None);
            security[0] = SecurityPermissionFlag.NoFlags;
            reflectionIndex++;
            return false ;
        }
        security[0] = mySecurity[reflectionIndex++];
        try {
            securityPerm[0] = new SecurityPermission(security[0]);
            return true ;
        }
        catch(System.Exception e) {
            Console.WriteLine(("Cannot create SecurityPermission: " 
                + security[0] + " " + e));
            securityPerm[0] = new SecurityPermission(PermissionState.None);
            security[0] = SecurityPermissionFlag.NoFlags;
            return true ;
        }
    } //CreateSecurity
} //SecurityGenerator

System.Object
   System.Security.CodeAccessPermission
    System.Security.Permissions.SecurityPermission

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft