現在のアクセス許可が、指定したアクセス許可のサブセットかどうかを判断します。
Overrides Public Function IsSubsetOf( _
ByVal target As IPermission _) As Boolean Implements IPermission.IsSubsetOf
[C#]
public override bool IsSubsetOf(IPermissiontarget);
[C++]
public: bool IsSubsetOf(IPermission* target);
[JScript]
public override function IsSubsetOf(
target : IPermission) : Boolean;
パラメータ
- target
サブセットの関係を調べる対象のアクセス許可。これは、現在のアクセス許可と同じ型であることが必要です。
戻り値
現在のアクセス許可が、指定したアクセス許可のサブセットである場合は true 。それ以外の場合は false 。
実装
例外
例外の種類 | 条件 |
---|---|
ArgumentException | target パラメータが null 参照 (Visual Basic では Nothing) ではなく、現在のアクセス許可と同じ型でもありません。 |
解説
現在のアクセス許可で指定される状態が、指定したアクセス許可に完全に含まれる場合、現在のアクセス許可は指定したアクセス許可のサブセットです。たとえば、C:\example.txt へのアクセス権を表すアクセス許可は、C:\ へのアクセス権を表すアクセス許可のサブセットです。このメソッドが true を返す場合、現在のアクセス許可は、保護されたリソースに対するアクセス権を指定したアクセス許可と同じにしか表しません。
使用例
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
Private Function IsSubsetOfDemo() As Boolean
Dim returnValue As Boolean = True
Dim env1, env2 As String
Dim envPerm1, envPerm2 As EnvironmentPermission
Dim envGen1 As New EnvGenerator()
Dim envGen2 As New EnvGenerator()
envGen1.ResetIndex()
While envGen1.CreateEnv(envPerm1, env1, EnvironmentPermissionAccess.Read)
If envPerm1 Is Nothing Then
GoTo ContinueWhile1
End If
Console.WriteLine("**********************************************************" & ControlChars.Lf)
envGen2.ResetIndex()
While envGen2.CreateEnv(envPerm2, env2, EnvironmentPermissionAccess.AllAccess)
Dim firstPermission As String = IIf(env1 = "" Or env1 Is Nothing, "null", env1)
Dim secondPermission As String = IIf(env2 = "" Or env2 Is Nothing, "null", env2)
If envPerm2 Is Nothing Then
GoTo ContinueWhile2
End If
Try
If envPerm1.IsSubsetOf(envPerm2) Then
Console.WriteLine((firstPermission & " is a subset of " & secondPermission & ControlChars.Lf))
Else
Console.WriteLine((firstPermission & " is not a subset of " & secondPermission & ControlChars.Lf))
End If
Catch e As Exception
Console.WriteLine(IIf("An exception was thrown for subset :" & env1 = "", "null", IIf(env1 & ControlChars.Lf & env2 = "", "null.", env2 & ControlChars.Lf & e.ToString())))
End Try
ContinueWhile2:
End While
ContinueWhile1:
End While
Return returnValue
End Function 'IsSubsetOfDemo
[C#]
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private bool IsSubsetOfDemo()
{
bool returnValue = true;
string env1,env2;
EnvironmentPermission envPerm1,envPerm2;
EnvGenerator envGen1 = new EnvGenerator();
EnvGenerator envGen2 = new EnvGenerator();
envGen1.ResetIndex();
while(envGen1.CreateEnv(out envPerm1, out env1, EnvironmentPermissionAccess.Read))
{
if(envPerm1 == null) continue;
Console.WriteLine("**********************************************************\n");
envGen2.ResetIndex();
while(envGen2.CreateEnv(out envPerm2, out env2, EnvironmentPermissionAccess.AllAccess))
{
string firstPermission = env1 == "" | env1 == null ? "null" : env1 ;
string secondPermission = env2 == "" | env2 == null ? "null" : env2;
if(envPerm2 == null) continue;
try
{
if (envPerm1.IsSubsetOf(envPerm2))
{
Console.WriteLine(firstPermission +" is a subset of "
+ secondPermission + "\n");
}
else
{
Console.WriteLine(firstPermission +" is not a subset of "
+ secondPermission + "\n");
}
}
catch(Exception e)
{
Console.WriteLine("An exception was thrown for subset :"
+ env1 == "" ? "null" : env1 + "\n" + env2 == "" ? "null." : env2 +"\n" + e);
}
}
}
return returnValue;
}
[C++]
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private:
bool IsSubsetOfDemo() {
bool returnValue = true;
String* env1, *env2;
EnvironmentPermission* envPerm1, *envPerm2;
EnvGenerator* envGen1 = new EnvGenerator();
EnvGenerator* envGen2 = new EnvGenerator();
envGen1->ResetIndex();
while(envGen1->CreateEnv(&envPerm1, &env1, EnvironmentPermissionAccess::Read)) {
if (envPerm1 == 0) continue;
Console::WriteLine(S"**********************************************************\n");
envGen2->ResetIndex();
while(envGen2->CreateEnv(&envPerm2, &env2, EnvironmentPermissionAccess::AllAccess)) {
String* firstPermission = env1->Equals(S"") || env1 == 0 ? S"null" : env1 ;
String* secondPermission = env2->Equals(S"") || env2 == 0 ? S"null" : env2;
if (envPerm2 == 0) continue;
try {
if (envPerm1->IsSubsetOf(envPerm2)) {
Console::WriteLine(S"{0} is a subset of {1}\n", firstPermission, secondPermission);
} else {
Console::WriteLine(S"{0} is not a subset of {1}\n", firstPermission, secondPermission);
}
} catch (Exception* e) {
Console::WriteLine(S"An exception was thrown for subset : {0}\n{1}\n{2}",
env1->Equals(S"") ? S"null" : env1,
env2->Equals(S"") ? S"null" : env2, e);
}
}
}
return returnValue;
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard
参照
EnvironmentPermission クラス | EnvironmentPermission メンバ | System.Security.Permissions 名前空間