IPermission.IsSubsetOf(IPermission) Méthode

Définition

Détermine si l’autorisation actuelle est un sous-ensemble de l’autorisation spécifiée.

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

Paramètres

target
IPermission

Autorisation qui doit être testée pour la relation de sous-ensemble. Cette autorisation doit être du même type que l’autorisation actuelle.

Retours

true si l’autorisation actuelle est un sous-ensemble de l’autorisation spécifiée ; sinon, false.

Exceptions

Le paramètre target n’a pas la valeur null et n’est pas du même type que l’autorisation actuelle.

Exemples

L’exemple de code suivant illustre l’implémentation de la IsSubsetOf méthode. Cet exemple de code fait partie d’un exemple plus grand fourni pour la IPermission classe .

    // Called by the Demand method: returns true 
    // if 'this' is a subset of 'target'.
public:
    virtual bool IsSubsetOf(IPermission^ target) override
    {
        // If 'target' is null and this permission allows nothing, 
        // return true.
        if (target == nullptr)
        {
            return (int)stateFlags == 0;
        }

        // Both objects must be the same type.
        SoundPermission^ soundPerm = VerifyTypeMatch(target);

        // Return true if the permissions of 'this' 
        // is a subset of 'target'.
        return stateFlags <= soundPerm->stateFlags;
    }
// Called by the Demand method: returns true if 'this' is a subset of 'target'.
public override Boolean IsSubsetOf(IPermission target)
{
    // If 'target' is null and this permission allows nothing, return true.
    if (target == null) return m_flags == 0;

    // Both objects must be the same type.
    SoundPermission soundPerm = VerifyTypeMatch(target);

    // Return true if the permissions of 'this' is a subset of 'target'.
    return m_flags <= soundPerm.m_flags;
}
' Called by the Demand method: returns true if 'this' is a subset of 'target'.
Public Overrides Function IsSubsetOf(ByVal target As IPermission) As [Boolean]
    ' If 'target' is null and this permission allows nothing, return true.
    If target Is Nothing Then
        Return m_flags = 0
    End If
    ' Both objects must be the same type.
    Dim soundPerm As SoundPermission = VerifyTypeMatch(target)

    ' Return true if the permissions of 'this' is a subset of 'target'.
    Return m_flags <= soundPerm.m_flags

End Function 'IsSubsetOf

Remarques

L’autorisation actuelle est un sous-ensemble de l’autorisation spécifiée si l’autorisation actuelle spécifie un ensemble d’opérations qui est entièrement contenu par l’autorisation spécifiée. Par exemple, une autorisation qui représente l’accès à C:\example.txt est un sous-ensemble d’une autorisation qui représente l’accès à C:\. Si cette méthode retourne true, l’autorisation actuelle ne représente pas plus d’accès à la ressource protégée que l’autorisation spécifiée.

Les instructions suivantes doivent avoir la valeur true pour toutes les implémentations de la IsSubsetOf méthode. X, Yet représentent des IPermission objets qui ne sont nullZ pas .

  • X. IsSubsetOf(X) retourne true.

  • X. IsSubsetOf(Y) retourne la même valeur que Y. IsSubsetOf(X) si et uniquement si X et Y représentent le même ensemble d’autorisations.

  • Si X. IsSubsetOf(Y) et Y. IsSubsetOf(Z) retourne truetous deux , X. IsSubsetOf(Z) retourne true.

Si X représente un objet vide IPermission avec un état d’autorisation de None et Y représente un IPermission objet qui est null, X. IsSubsetOf(Y) retourne true. Si Z est également une autorisation vide, l’opération Xde jeu composé . Union(Z). IsSubsetOf(Y) retourne true également, car l’union de deux autorisations vides est une autorisation vide.

S’applique à