CodeAccessPermission.IsSubsetOf(IPermission) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Quando implementata da una classe derivata, determina se l'autorizzazione corrente è un sottoinsieme dell'autorizzazione specificata.
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
Parametri
- target
- IPermission
Autorizzazione da testare per la relazione del subset. Questa autorizzazione deve essere dello stesso tipo di quella corrente.
Restituisce
true
se l'autorizzazione corrente è un subset di quella specificata; in caso contrario, false
.
Implementazioni
Eccezioni
Il parametro target
non è null
e non è dello stesso tipo dell'autorizzazione corrente.
Esempio
Nell'esempio IsSubsetOf di codice seguente viene illustrato un override del metodo. Questo esempio di codice fa parte di un esempio più grande fornito per la CodeAccessPermission classe.
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
Commenti
L'autorizzazione corrente è un subset dell'autorizzazione specificata se l'autorizzazione corrente specifica un set di operazioni interamente contenuto dall'autorizzazione specificata. Ad esempio, un'autorizzazione che rappresenta l'accesso a C:\example.txt è un subset di un'autorizzazione che rappresenta l'accesso a C:\. Se questo metodo restituisce true
, l'autorizzazione corrente non rappresenta più l'accesso alla risorsa protetta rispetto all'autorizzazione specificata.
Per tutte le sostituzioni del IsSubsetOf metodo sono necessarie true
le istruzioni seguenti. X, Y e Z rappresentano oggetti di autorizzazione di accesso al codice personalizzati che non sono riferimenti Null, U rappresenta un'autorizzazione di accesso al codice senza restrizioni e N rappresenta un'autorizzazione vuota con un PermissionState oggetto .None
X. IsSubsetOf(X) restituisce
true
.X. IsSubsetOf(Y) restituisce lo stesso valore di Y. IsSubsetOf(X) se e solo se X e Y rappresentano lo stesso set di autorizzazioni.
Se X. IsSubsetOf(Y) e Y. IsSubsetOf(Z) restituisce
true
, X. IsSubsetOf(Z) restituiscetrue
.X. IsSubsetOf(U) restituisce
true
.X. IsSubsetOf(N) restituisce
false
.N. IsSubsetOf(X) restituisce
true
.
Se X e Y rappresentano oggetti di autorizzazione di accesso al codice personalizzati che sono riferimenti Null, X. IsSubsetOf(Y) restituisce true
. Se Z è anche Null, l'operazione del set composto X. Union(Y). IsSubsetOf(Z) restituisce true
anche perché l'unione di due autorizzazioni Null è un'autorizzazione Null.
Note per gli implementatori
È necessario eseguire l'override di questo metodo in una classe derivata.