FileDialogPermission.Intersect 方法
创建并返回一个权限,该权限是当前权限和指定权限的交集。
**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Overrides Function Intersect ( _
target As IPermission _
) As IPermission
用法
Dim instance As FileDialogPermission
Dim target As IPermission
Dim returnValue As IPermission
returnValue = instance.Intersect(target)
public override IPermission Intersect (
IPermission target
)
public:
virtual IPermission^ Intersect (
IPermission^ target
) override
public IPermission Intersect (
IPermission target
)
public override function Intersect (
target : IPermission
) : IPermission
参数
- target
要与当前权限相交的权限。它必须与当前权限属于同一类型。
返回值
一个新权限,它表示当前权限与指定权限的交集。如果交集为空,则此新权限为 空引用(在 Visual Basic 中为 Nothing)。
异常
异常类型 | 条件 |
---|---|
target 参数不是 空引用(在 Visual Basic 中为 Nothing),而且与当前权限不是同一类型。 |
备注
两个权限的交集是一个权限,用于描述它们共同描述的一套操作。只有同时通过两个原始权限的请求才能通过该交集。
示例
下面的代码示例旨在演示 Intersect 方法的行为,而不演示其用法。一般情况下,权限类的方法由安全性基础结构使用,而不在应用程序中使用。但是,下面的代码示例将演示在从您的代码执行该方法时,该方法将如何执行。有关完整的代码示例,请参见 FileDialogPermission 类。
Private Function IntersectDemo() As Boolean
Dim returnValue As Boolean = True
fileDialogPerm3 = CType(fileDialogPerm1.Intersect(fileDialogPerm2), FileDialogPermission)
If Not (fileDialogPerm3 Is Nothing) Then
Console.WriteLine("The intersection of " + fileDialogPerm1.Access.ToString() + " and " _
+ fileDialogPerm2.Access.ToString() + " = " + CType(fileDialogPerm3, _
FileDialogPermission).Access.ToString())
Else
Console.WriteLine("The intersection of " + fileDialogPerm1.Access.ToString() + " and " + _
fileDialogPerm2.Access + " is null.")
End If
Return returnValue
End Function 'IntersectDemo
private bool IntersectDemo()
{
bool returnValue = true;
fileDialogPerm3 = (FileDialogPermission)fileDialogPerm1.Intersect(fileDialogPerm2);
if (fileDialogPerm3 != null)
{
Console.WriteLine("The intersection of " + fileDialogPerm1.Access +
" and " + fileDialogPerm2.Access + " = " +
((FileDialogPermission)fileDialogPerm3).Access.ToString());
}
else
{
Console.WriteLine("The intersection of " + fileDialogPerm1.Access +
" and " + fileDialogPerm2.Access + " is null.");
}
return returnValue;
}
bool IntersectDemo()
{
bool returnValue = true;
FileDialogPermission^ fileDialogIdPerm1 =
gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
FileDialogPermission^ fileDialogIdPerm2 =
gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );
FileDialogPermission^ fileDialogIdPerm3 =
gcnew FileDialogPermission(PermissionState::None);
//Console.WriteLine("\tfileDialogIdPerm2 = " +fileDialogIdPerm2.ToString());
fileDialogIdPerm3 = dynamic_cast<FileDialogPermission^>(fileDialogIdPerm1->Intersect( fileDialogIdPerm2 ));
if ( fileDialogIdPerm3 != nullptr )
{
Console::WriteLine( "The intersection of {0} and {1} = {2}",
fileDialogIdPerm1->Access, fileDialogIdPerm2->Access, (dynamic_cast<FileDialogPermission^>(fileDialogIdPerm3))->Access );
}
else
{
Console::WriteLine( "The intersection of {0} and {1} is null.",
fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
}
return returnValue;
}
// Intersect creates and returns a new permission that is the
// intersection of the current
// permission and the permission specified.
private boolean IntersectDemo()
{
boolean returnValue = true;
FileDialogPermissionAccess fileDialog1[] =
new FileDialogPermissionAccess[1];
FileDialogPermissionAccess fileDialog2[] =
new FileDialogPermissionAccess[1];
FileDialogPermission fileDialogIdPerm1[] =
new FileDialogPermission[1];
FileDialogPermission fileDialogIdPerm2[] =
new FileDialogPermission[1];
FileDialogPermission fileDialogIdPerm3 = null;
FileDialogGenerator fileDialogGen1 =
new FileDialogGenerator();
FileDialogGenerator fileDialogGen2 =
new FileDialogGenerator();
fileDialogGen1.ResetIndex();
while(fileDialogGen1.CreateFileDialog(
fileDialogIdPerm1, fileDialog1)) {
if (fileDialogIdPerm1[0] == null) {
continue ;
}
Console.WriteLine("***************************"
+ "*******************************\n");
fileDialogGen2.ResetIndex();
while(fileDialogGen2.CreateFileDialog(
fileDialogIdPerm2, fileDialog2)) {
if (fileDialogIdPerm2[0] == null) {
continue ;
}
fileDialogIdPerm3 =((FileDialogPermission)
(fileDialogIdPerm1[0].Intersect
(fileDialogIdPerm2[0])));
if (fileDialogIdPerm3 != null) {
Console.WriteLine(("The intersection of "
+ fileDialog1[0] + " and " + fileDialog2[0]
+ " = " +((FileDialogPermission)(fileDialogIdPerm3)).
get_Access().ToString()));
}
else {
Console.WriteLine(("The intersection of "
+ fileDialog1[0] + " and " + fileDialog2[0]
+ " is null."));
}
}
}
return returnValue ;
} //IntersectDemo
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
FileDialogPermission 类
FileDialogPermission 成员
System.Security.Permissions 命名空间