Export (0) Print
Expand All

PublisherIdentityPermission.IsSubsetOf Method

Determines whether the current permission is a subset of the specified permission.

[Visual Basic]
Overrides Public Function IsSubsetOf( _
   ByVal target As IPermission _
) As Boolean Implements IPermission.IsSubsetOf
[C#]
public override bool IsSubsetOf(
 IPermission target
);
[C++]
public: bool IsSubsetOf(
 IPermission* target
);
[JScript]
public override function IsSubsetOf(
   target : IPermission
) : Boolean;

Parameters

target
A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission.

Return Value

true if the current permission is a subset of the specified permission; otherwise, false.

Implements

IPermission.IsSubsetOf

Exceptions

Exception Type Condition
ArgumentException The target parameter is not a null reference (Nothing in Visual Basic) and is not of the same type as the current permission.

Remarks

The current permission is a subset of the specified permission if the two permissions are equal. If this method returns true, the current permission represents the same access to the protected resource as the specified permission.

PublisherIdentityPermission supports set operations (IsSubsetOf, Intersect, and Union) only when the current permission is equal to the specified permission.

Example

[Visual Basic] 
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
Private Function IsSubsetOfDemo() As Boolean

    Dim retCode As Boolean = True

    Dim publisher1, publisher2 As [String]
    Dim pubIdPerm1, pubIdPerm2 As PublisherIdentityPermission

    Dim pubGen1 As New PublisherGenerator()
    Dim pubGen2 As New PublisherGenerator()

    pubGen1.ResetIndex()
    While pubGen1.CreatePublisher(pubIdPerm1, publisher1)
        If pubIdPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        pubGen2.ResetIndex()
        While pubGen2.CreatePublisher(pubIdPerm2, publisher2)
            If pubIdPerm2 Is Nothing Then
                GoTo ContinueWhile2
            End If
            Try
                ' Check for whether either of the publishers is null.
                ' An exception will be thrown if either is null.
                If publisher1 <> "null" AndAlso publisher2 <> "null" Then
                    If pubIdPerm1.IsSubsetOf(pubIdPerm2) Then
                        Console.WriteLine((pubIdPerm1.Certificate.GetName() & " is a subset of " & pubIdPerm2.Certificate.GetName() & ControlChars.Lf))
                    Else
                        Console.WriteLine((pubIdPerm1.Certificate.GetName() & " is not a subset of " & pubIdPerm2.Certificate.GetName() & ControlChars.Lf))
                    End If
                End If

            Catch
                Console.WriteLine(("An exception was thrown for " & publisher1 & " is a subset of " & publisher2 & ControlChars.Lf & "."))
                retCode = False
            End Try
ContinueWhile2:
        End While
ContinueWhile1:
    End While


    Return retCode
End Function 'IsSubsetOfDemo


[C#] 
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
    private bool IsSubsetOfDemo()
    {

        bool retCode = true;

        String publisher1,publisher2;
        PublisherIdentityPermission pubIdPerm1,pubIdPerm2;

        PublisherGenerator pubGen1 = new PublisherGenerator();
        PublisherGenerator pubGen2 = new PublisherGenerator();

        pubGen1.ResetIndex();
        while(pubGen1.CreatePublisher(out pubIdPerm1, out publisher1)) 
        {
            if(pubIdPerm1 == null) continue;
            pubGen2.ResetIndex();
            while(pubGen2.CreatePublisher(out pubIdPerm2, out publisher2)) 
            {
                if(pubIdPerm2 == null) continue;

                try
                {
                    // Check for whether either of the publishers is null.
                    // An exception will be thrown if either is null.
                    if (publisher1 != "null" && publisher2 != "null")  
                    {
                        if (pubIdPerm1.IsSubsetOf(pubIdPerm2))
                        {
                            Console.WriteLine(pubIdPerm1.Certificate.GetName() + 
                                " is a subset of " + pubIdPerm2.Certificate.GetName() + "\n");
                        }
                        else
                        {
                            Console.WriteLine(pubIdPerm1.Certificate.GetName()  + 
                                    " is not a subset of " + pubIdPerm2.Certificate.GetName() + "\n");
                        }
                    }

                }
                catch 
                {
                    Console.WriteLine("An exception was thrown for " + publisher1 + " is a subset of "  + 
                        publisher2 +"\n." );
                    retCode=false;
                }

            }
        }


        return retCode;
    }

[C++] 
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
bool IsSubsetOfDemo()
{

   bool retCode = true;

   String* publisher1;
   String* publisher2;

   PublisherIdentityPermission* pubIdPerm1;
   PublisherIdentityPermission* pubIdPerm2;


   PublisherGenerator* pubGen1 = new PublisherGenerator();
   PublisherGenerator* pubGen2 = new PublisherGenerator();

   pubGen1->ResetIndex();
   while(pubGen1->CreatePublisher(&pubIdPerm1, &publisher1)) 
   {
      if(pubIdPerm1 == 0) continue;
      pubGen2->ResetIndex();
      while(pubGen2->CreatePublisher(&pubIdPerm2, &publisher2)) 
      {
         if(pubIdPerm2 == 0) continue;

         try
         {
            // Check for whether either of the publishers is null.
            // An exception will be thrown if either is null.
            if (!publisher1->Equals(S"null") && !publisher2->Equals(S"null"))
            {
               if (pubIdPerm1->IsSubsetOf(pubIdPerm2))
               {
                  Console::WriteLine(S"{0} is a subset of {1}\n",
                     pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName());
               }
               else
               {
                  Console::WriteLine(S"{0} is not a subset of {1}\n",
                     pubIdPerm1->Certificate->GetName(), pubIdPerm2->Certificate->GetName());
               }
            }

         }
         catch (Exception*)
         {
            Console::WriteLine(S"An exception was thrown for {0} is a subset of {1}\n.",
               publisher1, publisher2 );
            retCode=false;
         }

      }
   }


   return retCode;
}

[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

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

Show:
© 2015 Microsoft