Export (0) Print
Expand All

SecurityPermission Constructor

.NET Framework 1.1

Initializes a new instance of the SecurityPermission class.

Overload List

Initializes a new instance of the SecurityPermission class with either restricted or unrestricted permission as specified.

[Visual Basic] Public Sub New(PermissionState)
[C#] public SecurityPermission(PermissionState);
[C++] public: SecurityPermission(PermissionState);
[JScript] public function SecurityPermission(PermissionState);

Initializes a new instance of the SecurityPermission class with the specified initial set state of the flags.

[Visual Basic] Public Sub New(SecurityPermissionFlag)
[C#] public SecurityPermission(SecurityPermissionFlag);
[C++] public: SecurityPermission(SecurityPermissionFlag);
[JScript] public function SecurityPermission(SecurityPermissionFlag);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the SecurityPermission constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' CreateSecurity creates a SecurityPermission object.
Public Function CreateSecurity(ByRef SecurityPerm As SecurityPermission, _
    ByRef Security As SecurityPermissionFlag) As Boolean

    If reflectionIndex >= mySecurity.Length Then
        SecurityPerm = New SecurityPermission(PermissionState.None)
        Security = SecurityPermissionFlag.NoFlags
        reflectionIndex &= 1
        Return False
    End If
    Security = mySecurity(reflectionIndex)
    reflectionIndex = reflectionIndex + 1
    Try
        SecurityPerm = New SecurityPermission(Security)
        Return True
    Catch e As Exception
        Console.WriteLine(("Cannot create SecurityPermission: " & Security & " " & e.ToString()))
        SecurityPerm = New SecurityPermission(PermissionState.None)
        Security = SecurityPermissionFlag.NoFlags
        Return True
    End Try
End Function 'CreateSecurity

[C#] 
// CreateSecurity creates a SecurityPermission object.
public bool CreateSecurity(out SecurityPermission SecurityPerm, out SecurityPermissionFlag Security)
{

    if(reflectionIndex >= mySecurity.Length) 
    {
        SecurityPerm = new SecurityPermission(PermissionState.None);
        Security=SecurityPermissionFlag.NoFlags;
        reflectionIndex++;
        return false;
    }
    Security = mySecurity[reflectionIndex++];
    try
    {
        SecurityPerm = new SecurityPermission(Security);
        return true;
    } 
    catch(Exception e)
    {
        Console.WriteLine("Cannot create SecurityPermission: " + Security +" "+e);
        SecurityPerm = new SecurityPermission(PermissionState.None);
        Security=SecurityPermissionFlag.NoFlags;
        return true;
    }
}

[C++] 
// CreateSecurity creates a SecurityPermission object.
bool CreateSecurity([Out] SecurityPermission** SecurityPerm, [Out] SecurityPermissionFlag* Security)
{

    if(reflectionIndex >= mySecurity->Length) 
    {
        *SecurityPerm = new SecurityPermission(PermissionState::None);
        *Security=SecurityPermissionFlag::NoFlags;
        reflectionIndex++;
        return false;
    }
    *Security = mySecurity[reflectionIndex++];
    try
    {
        *SecurityPerm = new SecurityPermission(*Security);
        return true;
    } 
    catch(Exception* e)
    {
        Console::WriteLine(S"Cannot create SecurityPermission: {0} {1}", __box(*Security), e);
        *SecurityPerm = new SecurityPermission(PermissionState::None);
        *Security=SecurityPermissionFlag::NoFlags;
        return true;
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

SecurityPermission Class | SecurityPermission Members | System.Security.Permissions Namespace

Show:
© 2014 Microsoft