CodeAccessPermission.IsSubsetOf(IPermission) Metodo
In questo articolo
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
- target
- IPermission
Autorizzazione da testare per la relazione del subset. Questa autorizzazione deve essere dello stesso tipo di quella corrente.
true
se l'autorizzazione corrente è un subset di quella specificata; in caso contrario, false
.
Il parametro target
non è null
e non è dello stesso tipo dell'autorizzazione corrente.
Nell'esempio di codice seguente viene illustrato un override del IsSubsetOf metodo . Questo esempio di codice fa parte di un esempio più ampio 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
L'autorizzazione corrente è un subset dell'autorizzazione specificata se l'autorizzazione corrente specifica un set di operazioni interamente contenute nell'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) restituiscono
true
entrambi , 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 di set composto X. Union(Y). IsSubsetOf(Z) restituisce true
anche perché l'unione di due autorizzazioni Null è un'autorizzazione Null.
È necessario eseguire l'override di questo metodo in una classe derivata.
Si applica a
Prodotto | Versioni |
---|---|
.NET | 8 (package-provided), 9 (package-provided), 10 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
Feedback su .NET
.NET è un progetto di open source. Selezionare un collegamento per fornire feedback: