CodeAccessPermission.IsSubsetOf(IPermission) Método

Definición

Cuando se implementa mediante una clase derivada, determina si el permiso actual es un subconjunto del permiso especificado.

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

Parámetros

target
IPermission

Permiso que se va a probar para la relación de subconjunto. Este permiso debe ser del mismo tipo que el permiso actual.

Devoluciones

Boolean

true si el permiso actual es un subconjunto del permiso especificado; si no, false.

Implementaciones

Excepciones

El parámetro target no es null y no es del mismo tipo que el permiso actual.

Ejemplos

En el ejemplo de código siguiente se muestra una invalidación del IsSubsetOf método . Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la CodeAccessPermission clase .

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

Comentarios

El permiso actual es un subconjunto del permiso especificado si el permiso actual especifica un conjunto de operaciones que contiene totalmente el permiso especificado. Por ejemplo, un permiso que representa el acceso a C:\example.txt es un subconjunto de un permiso que representa el acceso a C:\. Si este método devuelve true, el permiso actual no representa más acceso al recurso protegido que el permiso especificado.

Es necesario que las instrucciones siguientes sean true para todas las invalidaciones del IsSubsetOf método . X, Y y Z representan objetos de permiso de acceso de código personalizados que no son referencias nulas, U representa un permiso de acceso de código sin restricciones y N representa un permiso vacío con un PermissionState de None.

  • X. IsSubsetOf(X) devuelve true.

  • X. IsSubsetOf(Y) devuelve el mismo valor que Y. IsSubsetOf(X) si y solo si X e Y representan el mismo conjunto de permisos.

  • Si es X. IsSubsetOf(Y) e Y. IsSubsetOf(Z) devuelven true, X. IsSubsetOf(Z) devuelve true.

  • X. IsSubsetOf(U) devuelve true.

  • X. IsSubsetOf(N) devuelve false.

  • N. IsSubsetOf(X) devuelve true.

Si X e Y representan objetos de permiso de acceso de código personalizados que son referencias nulas, X. IsSubsetOf(Y) devuelve true. Si Z también es null, la operación de conjunto compuesto X. Union(Y). IsSubsetOf(Z) también devuelve true porque la unión de dos permisos NULL es un permiso NULL.

Notas a los implementadores

Debe invalidar este método en una clase derivada.

Se aplica a