CodeAccessPermission.IsSubsetOf(IPermission) Metoda

Definicja

Po zaimplementowaniu przez klasę pochodną określa, czy bieżące uprawnienie jest podzbiorem określonego uprawnienia.

public:
 abstract bool IsSubsetOf(System::Security::IPermission ^ target);
public abstract bool IsSubsetOf (System.Security.IPermission target);
abstract member IsSubsetOf : System.Security.IPermission -> bool
Public MustOverride Function IsSubsetOf (target As IPermission) As Boolean

Parametry

target
IPermission

Uprawnienie, które ma zostać przetestowane dla relacji podzestawu. To uprawnienie musi być tego samego typu co bieżące uprawnienie.

Zwraca

true jeśli bieżące uprawnienie jest podzbiorem określonego uprawnienia; w przeciwnym razie , false.

Implementuje

Wyjątki

Parametr target nie null jest i nie jest tego samego typu co bieżące uprawnienie.

Przykłady

Poniższy przykład kodu przedstawia zastąpienie IsSubsetOf metody . Ten przykład kodu jest częścią większego przykładu udostępnionego CodeAccessPermission dla klasy .

public:
   virtual bool IsSubsetOf( IPermission^ target ) override
   {
#if ( debug ) 
      Console::WriteLine( "************* Entering IsSubsetOf *********************" );
#endif

      if ( target == nullptr )
      {
         Console::WriteLine( "IsSubsetOf: target == null" );
         return false;
      }

#if ( debug ) 
      Console::WriteLine( "This is = {0}", ((NameIdPermission)this).Name );
      Console::WriteLine( "Target is {0}", ((NameIdPermission)target).m_Name );
#endif

      try
      {
         NameIdPermission^ operand = dynamic_cast<NameIdPermission^>(target);
         
         // The following check for unrestricted permission is only included as an example for
         // permissions that allow the unrestricted state. It is of no value for this permission.
         if ( true == operand->m_Unrestricted )
         {
            return true;
         }
         else if ( true == this->m_Unrestricted )
         {
            return false;
         }

         if ( this->m_Name != nullptr )
         {
            if ( operand->m_Name == nullptr )
            {
               return false;
            }
            if ( this->m_Name->Equals( "" ) )
            {
               return true;
            }
         }

         if ( this->m_Name->Equals( operand->m_Name ) )
         {
            return true;
         }
         else
         {
            // Check for wild card character '*'.
            int i = operand->m_Name->LastIndexOf( "*" );

            if ( i > 0 )
            {
               String^ prefix = operand->m_Name->Substring( 0, i );
               if ( this->m_Name->StartsWith( prefix ) )
               {
                  return true;
               }
            }
         }
         return false;
      }
      catch ( InvalidCastException^ ) 
      {
         throw gcnew ArgumentException( String::Format( "Argument_WrongType", this->GetType()->FullName ) );
      }
   }
        public override bool IsSubsetOf(IPermission target)
        {
#if(debug)
            Console.WriteLine ("************* Entering IsSubsetOf *********************");
#endif
            if (target == null)
            {
                Console.WriteLine ("IsSubsetOf: target == null");
                return false;
            }
#if(debug)

            Console.WriteLine ("This is = " + (( NameIdPermission)this).Name);
            Console.WriteLine ("Target is " + (( NameIdPermission)target).m_Name);
#endif
            try
            {
                 NameIdPermission operand = ( NameIdPermission)target;

                // The following check for unrestricted permission is only included as an example for
                // permissions that allow the unrestricted state. It is of no value for this permission.
                if (true == operand.m_Unrestricted)
                {
                    return true;
                }
                else if (true == this.m_Unrestricted)
                {
                    return false;
                }

                if (this.m_Name != null)
                {
                    if (operand.m_Name == null) return false;

                    if (this.m_Name == "") return true;
                }

                if (this.m_Name.Equals (operand.m_Name))
                {
                    return true;
                }
                else
                {
                    // Check for wild card character '*'.
                    int i = operand.m_Name.LastIndexOf ("*");

                    if (i > 0)
                    {
                        string prefix = operand.m_Name.Substring (0, i);

                        if (this.m_Name.StartsWith (prefix))
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
            catch (InvalidCastException)
            {
                throw new ArgumentException (String.Format ("Argument_WrongType", this.GetType ().FullName));
            }
        }
        Public Overrides Function IsSubsetOf(ByVal target As IPermission) As Boolean

#If (Debug) Then

            Console.WriteLine("************* Entering IsSubsetOf *********************")
#End If
            If target Is Nothing Then
                Console.WriteLine("IsSubsetOf: target == null")
                Return False
            End If
#If (Debug) Then
            Console.WriteLine(("This is = " + CType(Me, NameIdPermission).Name))
            Console.WriteLine(("Target is " + CType(target, NameIdPermission).m_name))
#End If
            Try
                Dim operand As NameIdPermission = CType(target, NameIdPermission)

                ' The following check for unrestricted permission is only included as an example for
                ' permissions that allow the unrestricted state. It is of no value for this permission.
                If True = operand.m_Unrestricted Then
                    Return True
                ElseIf True = Me.m_Unrestricted Then
                    Return False
                End If

                If Not (Me.m_name Is Nothing) Then
                    If operand.m_name Is Nothing Then
                        Return False
                    End If
                    If Me.m_name = "" Then
                        Return True
                    End If
                End If
                If Me.m_name.Equals(operand.m_name) Then
                    Return True
                Else
                    ' Check for wild card character '*'.
                    Dim i As Integer = operand.m_name.LastIndexOf("*")

                    If i > 0 Then
                        Dim prefix As String = operand.m_name.Substring(0, i)

                        If Me.m_name.StartsWith(prefix) Then
                            Return True
                        End If
                    End If
                End If

                Return False
            Catch
                Throw New ArgumentException(String.Format("Argument_WrongType", Me.GetType().FullName))
            End Try
        End Function

Uwagi

Bieżące uprawnienie jest podzbiorem określonego uprawnienia, jeśli bieżące uprawnienie określa zestaw operacji, które są całkowicie zawarte przez określone uprawnienie. Na przykład uprawnienie reprezentujące dostęp do C:\example.txt jest podzbiorem uprawnienia reprezentującego dostęp do C:\. Jeśli ta metoda zwróci truewartość , bieżące uprawnienie nie reprezentuje więcej dostępu do chronionego zasobu niż określone uprawnienie.

Dla wszystkich przesłonięć true metody wymagane są następujące instrukcje IsSubsetOf . X, Y i Z reprezentują niestandardowe obiekty uprawnień dostępu do kodu, które nie są odwołaniami o wartości null, U reprezentuje nieograniczone uprawnienie dostępu do kodu, a N reprezentuje puste uprawnienie z wartością PermissionStateNone.

  • X. Funkcja IsSubsetOf(X) zwraca wartość true.

  • X. Funkcja IsSubsetOf(Y) zwraca tę samą wartość co Y. IsSubsetOf(X) jeśli i tylko wtedy, gdy X i Y reprezentują ten sam zestaw uprawnień.

  • Jeśli X. IsSubsetOf(Y) i Y. IsSubsetOf(Z) zwraca wartość true, X. Funkcja IsSubsetOf(Z) zwraca wartość true.

  • X. Funkcja IsSubsetOf(U) zwraca wartość true.

  • X. Funkcja IsSubsetOf(N) zwraca wartość false.

  • N. Funkcja IsSubsetOf(X) zwraca wartość true.

Jeśli wartości X i Y reprezentują niestandardowe obiekty uprawnień dostępu do kodu, które są odwołaniami o wartości null, X. Funkcja IsSubsetOf(Y) zwraca wartość true. Jeśli Z ma również wartość null, operacja zestawu złożonego X. Union(Y). Funkcja IsSubsetOf(Z) zwraca również, true ponieważ połączenie dwóch uprawnień o wartości null jest uprawnieniem o wartości null.

Uwagi dotyczące implementowania

Tę metodę należy zastąpić w klasie pochodnej.

Dotyczy