Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Flags Property
Collapse the table of content
Expand the table of content

SecurityPermission.Flags Property

Gets or sets the security permission flags.

[Visual Basic]
Public Property Flags As SecurityPermissionFlag
[C#]
public SecurityPermissionFlag Flags {get; set;}
[C++]
public: __property SecurityPermissionFlag get_Flags();
public: __property void set_Flags(SecurityPermissionFlag);
[JScript]
public function get Flags() : SecurityPermissionFlag;
public function set Flags(SecurityPermissionFlag);

Property Value

The state of the current permission, represented by a bitwise OR combination of any permission bits defined by SecurityPermissionFlag.

Exceptions

Exception Type Condition
ArgumentException An attempt is made to set this property to an invalid value. See SecurityPermissionFlag for the valid values.

Remarks

Individual permission bits can be determined by performing an AND operation against this value and checking for nonzero.

Example

[Visual Basic] 
' 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.CreateSecurity(SecurityPerm1, Security1)
        If SecurityPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        SecurityGen2.ResetIndex()
        Console.WriteLine("********************************************************" & ControlChars.Lf)

        While SecurityGen2.CreateSecurity(SecurityPerm2, Security2)
            If SecurityPerm2 Is Nothing Then
                GoTo ContinueWhile2
            End If
            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


[C#] 
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private bool IsSubsetOfDemo()
{
    bool returnValue = true;
    SecurityPermissionFlag Security1,Security2;
    SecurityPermission SecurityPerm1,SecurityPerm2;
    SecurityGenerator SecurityGen1 = new SecurityGenerator();
    SecurityGenerator SecurityGen2 = new SecurityGenerator();
    SecurityGen1.ResetIndex();
    while(SecurityGen1.CreateSecurity(out SecurityPerm1, out Security1)) 
    {
        if(SecurityPerm1 == null) continue;
        SecurityGen2.ResetIndex();
        Console.WriteLine("********************************************************\n");

        while(SecurityGen2.CreateSecurity(out SecurityPerm2, out Security2)) 
        {
            if(SecurityPerm2 == null) continue;
            try
            {            
                if (SecurityPerm1.IsSubsetOf(SecurityPerm2))
                {
                    Console.WriteLine(SecurityPerm1.Flags + " is a subset of " + 
                        SecurityPerm2.Flags);
                }
                else
                {
                    Console.WriteLine(SecurityPerm1.Flags + " is not a subset of " + 
                        SecurityPerm2.Flags);
                }
            }
            catch(Exception e) 
            {
                Console.WriteLine("An exception was thrown for subset :" + SecurityPerm1 + "\n" + 
                    SecurityPerm2 +"\n" + e);
                returnValue=false;
            }
        }
    }
    return returnValue;
}

[C++] 
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private:
bool IsSubsetOfDemo()
{
    bool returnValue = true;
    SecurityPermissionFlag Security1,Security2;
    SecurityPermission* SecurityPerm1;
    SecurityPermission* SecurityPerm2;
    SecurityGenerator* SecurityGen1 = new SecurityGenerator();
    SecurityGenerator* SecurityGen2 = new SecurityGenerator();
    SecurityGen1->ResetIndex();
    while(SecurityGen1->CreateSecurity(&SecurityPerm1, &Security1)) 
    {
        if(SecurityPerm1 == 0) continue;
        SecurityGen2->ResetIndex();
        Console::WriteLine(S"********************************************************\n");

        while(SecurityGen2->CreateSecurity(&SecurityPerm2, &Security2)) 
        {
            if(SecurityPerm2 == 0) continue;
            try
            {            
                if (SecurityPerm1->IsSubsetOf(SecurityPerm2))
                {
                    Console::WriteLine(S"{0} is a subset of {1}",
                        __box(SecurityPerm1->Flags), __box(SecurityPerm2->Flags));
                }
                else
                {
                    Console::WriteLine(S"{0} is not a subset of {1}",
                        __box(SecurityPerm1->Flags), __box(SecurityPerm2->Flags));
                }
            }
            catch(Exception* e) 
            {
                Console::WriteLine(S"An exception was thrown for subset :{0}\n{1}\n{2}",
                    SecurityPerm1, SecurityPerm2, e);
                returnValue=false;
            }
        }
    }
    return returnValue;
}

[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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

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

Show:
© 2015 Microsoft