FileDialogPermission.IsSubsetOf 方法

确定当前权限是否为指定权限的子集。

**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Overrides Function IsSubsetOf ( _
    target As IPermission _
) As Boolean
用法
Dim instance As FileDialogPermission
Dim target As IPermission
Dim returnValue As Boolean

returnValue = instance.IsSubsetOf(target)
public override bool IsSubsetOf (
    IPermission target
)
public:
virtual bool IsSubsetOf (
    IPermission^ target
) override
public boolean IsSubsetOf (
    IPermission target
)
public override function IsSubsetOf (
    target : IPermission
) : boolean

参数

  • target
    将要测试子集关系的权限。此权限必须与当前权限属于同一类型。

返回值

如果当前权限是指定权限的子集,则为 true;否则为 false

异常

异常类型 条件

ArgumentException

target 参数不是 空引用(在 Visual Basic 中为 Nothing),而且与当前权限不是同一类型。

备注

如果当前权限指定的一组操作完全包含在指定的权限中,则当前权限是指定权限的一个子集。例如,Open 访问权限是 OpenSave 访问权限的子集。

示例

下面的代码示例旨在演示 IsSubsetOf 方法的行为,而不演示其用法。一般情况下,权限类的方法由安全性基础结构使用,而不在应用程序中使用。但是,下面的代码示例将演示在从您的代码执行该方法时,该方法将如何执行。有关完整的代码示例,请参见 FileDialogPermission 类。

Private Function IsSubsetOfDemo() As Boolean 
    Dim returnValue As Boolean = True
    
    
    If fileDialogPerm1.IsSubsetOf(fileDialogPerm2) Then
        Console.WriteLine(fileDialogPerm1.Access.ToString() + " is a subset of " _
        + fileDialogPerm2.Access.ToString())
    Else
        Console.WriteLine(fileDialogPerm1.Access.ToString + " is not a subset of " + _
        fileDialogPerm2.Access.ToString())
    End If
    
    Return returnValue

End Function 'IsSubsetOfDemo
private bool IsSubsetOfDemo()
{
    bool returnValue = true;


    if (fileDialogPerm1.IsSubsetOf(fileDialogPerm2))
    {
        Console.WriteLine(fileDialogPerm1.Access + " is a subset of " +
            fileDialogPerm2.Access);
    }
    else
    {
                    Console.WriteLine(fileDialogPerm1.Access + " is not a subset of " +
                        fileDialogPerm2.Access);
                }

    return returnValue;
}
bool IsSubsetOfDemo()
{
    bool returnValue = true;
    FileDialogPermission^ fileDialogIdPerm1 = gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
    FileDialogPermission^ fileDialogIdPerm2 = gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );
    if ( fileDialogIdPerm1->IsSubsetOf( fileDialogIdPerm2 ) )
    {
        Console::WriteLine( "{0} is a subset of {1}", fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
    }
    else
    {
        Console::WriteLine( "{0} is not a subset of {1}", fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
    }

    return returnValue;
}

// IsSubsetOf determines whether the current permission is a subset of the
// specified permission.
private boolean IsSubsetOfDemo() 
{
    boolean returnValue = true;
    FileDialogPermissionAccess fileDialog1[] = 
        new FileDialogPermissionAccess[1];
    FileDialogPermissionAccess fileDialog2[] = 
        new FileDialogPermissionAccess[1];
    FileDialogPermission fileDialogIdPerm1[] = 
        new FileDialogPermission[1];
    FileDialogPermission fileDialogIdPerm2[] = 
        new FileDialogPermission[1];
    FileDialogGenerator fileDialogGen1 =  
        new FileDialogGenerator();
    FileDialogGenerator fileDialogGen2 =  
        new FileDialogGenerator();
    fileDialogGen1.ResetIndex();
    while(fileDialogGen1.CreateFileDialog
        (fileDialogIdPerm1, fileDialog1)) {
        if (fileDialogIdPerm1[0] == null) {
            continue ;
        }
        fileDialogGen2.ResetIndex();
        Console.WriteLine("**********************" 
            + "**********************************\n");
        
        while(fileDialogGen2.CreateFileDialog(
            fileDialogIdPerm2, fileDialog2)) {
            if (fileDialogIdPerm2[0] == null) {
                continue ;
            }
            try {
                if (fileDialogIdPerm1[0].
                    IsSubsetOf(fileDialogIdPerm2[0])) {
                    Console.WriteLine((fileDialogIdPerm1[0].get_Access() 
                        + " is a subset of " 
                        + fileDialogIdPerm2[0].get_Access()));
                }
                else {
                    Console.WriteLine((fileDialogIdPerm1[0].get_Access() 
                        + " is not a subset of " + 
                    fileDialogIdPerm2[0].get_Access()));
                }
            }
            catch(System.Exception  e){
                Console.WriteLine(("An exception was thrown " 
                    + "for subset :" + fileDialogIdPerm1[0] 
                    + "\n" + fileDialogIdPerm2[0] + "\n" + e));
                    returnValue = false;
            }
        }
    }
    return returnValue ;
} //IsSubsetOfDemo

平台

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 命名空间