EnvironmentPermission.Union メソッド
現在のアクセス許可と指定したアクセス許可の和集合を表すアクセス許可を作成します。
Overrides Public Function Union( _
ByVal other As IPermission _) As IPermission Implements IPermission.Union
[C#]
public override IPermission Union(IPermissionother);
[C++]
public: IPermission* Union(IPermission* other);
[JScript]
public override function Union(
other : IPermission) : IPermission;
パラメータ
- other
現在のアクセス許可と和集合を持つアクセス許可。これは、現在のアクセス許可と同じ型であることが必要です。
戻り値
現在のアクセス許可と指定したアクセス許可の和集合を表す新しいアクセス許可。
実装
例外
例外の種類 | 条件 |
---|---|
ArgumentException | other パラメータが null 参照 (Visual Basic では Nothing) ではなく、現在のアクセス許可と同じ型でもありません。 |
解説
Union を呼び出すと、現在のアクセス許可と指定したアクセス許可の両方が表す状態をすべて表すアクセス許可が作成されます。いずれかのアクセス許可を要求し、その要求が満たされた場合、両者の和集合を表すアクセス許可に対する要求も満たされます。
使用例
' Union creates a new permission that is the union of the current permission and the specified permission.
Private Function UnionDemo() As Boolean
Dim returnValue As Boolean = True
Dim env1, env2 As String
Dim envPerm1, envPerm2 As EnvironmentPermission
Dim envIdPerm3 As IPermission
Dim envGen1 As New EnvGenerator()
Dim envGen2 As New EnvGenerator()
envGen1.ResetIndex()
While envGen1.CreateEnv(envPerm1, env1, EnvironmentPermissionAccess.Read)
If env1 Is Nothing Then
GoTo ContinueWhile1
End If
Console.WriteLine("**********************************************************" & ControlChars.Lf)
envGen2.ResetIndex()
While envGen2.CreateEnv(envPerm2, env2, EnvironmentPermissionAccess.Read)
Try
If envPerm2 Is Nothing Then
GoTo ContinueWhile2
End If
Dim firstPermission As String = IIf(env1 = "" Or env1 Is Nothing, "null", env1)
Dim secondPermission As String = IIf(env2 = "" Or env2 Is Nothing, "null", env2)
envIdPerm3 = CType(envPerm1.Union(envPerm2), EnvironmentPermission)
envIdPerm3 = envPerm1.Union(envPerm2)
If envIdPerm3 Is Nothing Then
Console.WriteLine(("The union of " & firstPermission & " and " & secondPermission & " is null."))
Else
Console.WriteLine(("The union of " & firstPermission & " and " & secondPermission & " = " & CType(envIdPerm3, EnvironmentPermission).GetPathList(EnvironmentPermissionAccess.Read).ToString()))
End If
Catch e As Exception
Console.WriteLine(("An exception was thrown for union " & e.ToString()))
returnValue = False
End Try
ContinueWhile2:
End While
ContinueWhile1:
End While
Return returnValue
End Function 'UnionDemo
[C#]
// Union creates a new permission that is the union of the current permission and the specified permission.
private bool UnionDemo()
{
bool returnValue = true;
string env1,env2;
EnvironmentPermission envPerm1,envPerm2;
IPermission envIdPerm3;
EnvGenerator envGen1 = new EnvGenerator();
EnvGenerator envGen2 = new EnvGenerator();
envGen1.ResetIndex();
while(envGen1.CreateEnv(out envPerm1, out env1, EnvironmentPermissionAccess.Read))
{
if(env1 == null) continue;
Console.WriteLine("**********************************************************\n");
envGen2.ResetIndex();
while(envGen2.CreateEnv(out envPerm2, out env2, EnvironmentPermissionAccess.Read))
{
try
{
if(envPerm2 == null) continue;
string firstPermission = env1 == "" | env1 == null ? "null" : env1 ;
string secondPermission = env2 == "" | env2 == null ? "null" : env2;
envIdPerm3 = (EnvironmentPermission)envPerm1.Union(envPerm2);
envIdPerm3 = envPerm1.Union(envPerm2);
if(envIdPerm3 == null)
{
Console.WriteLine("The union of " + firstPermission + " and "
+ secondPermission + " is null.");
}
else
{
Console.WriteLine("The union of " + firstPermission + " and "
+ secondPermission +
" = " + ((EnvironmentPermission)envIdPerm3).GetPathList(EnvironmentPermissionAccess.Read).ToString());
}
}
catch(Exception e)
{
Console.WriteLine("An exception was thrown for union " + e);
returnValue=false;
}
}
}
return returnValue;
}
[C++]
// Union creates a new permission that is the union of the current permission and the specified permission.
private:
bool UnionDemo() {
bool returnValue = true;
String* env1, *env2;
EnvironmentPermission* envPerm1, *envPerm2;
IPermission* envIdPerm3;
EnvGenerator* envGen1 = new EnvGenerator();
EnvGenerator* envGen2 = new EnvGenerator();
envGen1->ResetIndex();
while(envGen1->CreateEnv(&envPerm1, &env1, EnvironmentPermissionAccess::Read)) {
if (env1 == 0) continue;
Console::WriteLine(S"**********************************************************\n");
envGen2->ResetIndex();
while(envGen2->CreateEnv(&envPerm2, &env2, EnvironmentPermissionAccess::Read)) {
try {
if (envPerm2 == 0) continue;
String* firstPermission = env1->Equals(S"") || env1 == 0 ? S"null" : env1 ;
String* secondPermission = env2->Equals(S"") || env2 == 0 ? S"null" : env2;
envIdPerm3 = dynamic_cast<EnvironmentPermission*>(envPerm1->Union(envPerm2));
envIdPerm3 = envPerm1->Union(envPerm2);
if (envIdPerm3 == 0) {
Console::WriteLine(S"The union of {0} and {1} is null.", firstPermission, secondPermission);
} else {
Console::WriteLine(S"The union of {0} and {1} = {2}", firstPermission, secondPermission,
(dynamic_cast<EnvironmentPermission*>(envIdPerm3))->GetPathList(EnvironmentPermissionAccess::Read));
}
} catch (Exception* e) {
Console::WriteLine(S"An exception was thrown for union {0}", e);
returnValue=false;
}
}
}
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 名前空間