次の方法で共有


ResourcePermissionBase クラス

コード アクセス セキュリティ アクセス許可を制御できるようにします。

この型のすべてのメンバの一覧については、ResourcePermissionBase メンバ を参照してください。

System.Object
   System.Security.CodeAccessPermission
      System.Security.Permissions.ResourcePermissionBase
         System.Diagnostics.EventLogPermission
         System.Diagnostics.PerformanceCounterPermission
         System.DirectoryServices.DirectoryServicesPermission
         System.ServiceProcess.ServiceControllerPermission

<Serializable>
MustInherit Public Class ResourcePermissionBase   Inherits CodeAccessPermission   Implements IUnrestrictedPermission
[C#]
[Serializable]
public abstract class ResourcePermissionBase :   CodeAccessPermission, IUnrestrictedPermission
[C++]
[Serializable]
public __gc __abstract class ResourcePermissionBase : public   CodeAccessPermission, IUnrestrictedPermission
[JScript]
public
   Serializable
abstract class ResourcePermissionBase extends   CodeAccessPermission implements IUnrestrictedPermission

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

継承時の注意: ResourcePermissionBase から継承する場合は、少なくとも 3 つのコンストラクタを用意し、2 つのプロパティを設定して、3 番目のプロパティを指定する必要があります。必要なコンストラクタは、既定のコンストラクタ、パラメータとして PermissionState を取得するコンストラクタ、およびプロパティの値を取得するための、必要な数のコンストラクタです。設定する必要があるプロパティは、 PermissionAccessTypeTagNames です。必要な 3 番目のプロパティは、アクセス許可エントリを返すプロパティです。このクラスの実装例については、 PerformanceCounterPermission のトピックを参照してください。 PerformanceCounterPermission では、 TagNames プロパティが "Machine" と "Category" にプライベートに設定され、 PermissionAccessType プロパティが PerformanceCounterPermissionAccess の型にプライベートに設定され、 PermissionEntries プロパティがアクセス許可エントリを返します。

使用例

[Visual Basic, C#, C++] ResourcePermissionBase クラスから継承する例を次に示します。4 種類のコンストラクタが実装されています。この例では、 MailslotPermissionEntry というクラスの実装も提供されています。次に、 PermissionAccessType プロパティが MailslotPermissionEntry の型にプライベートに設定されます。 TagNames プロパティは "Name" と "Machine" にプライベートに設定されます。

 
Imports System
Imports System.Security.Permissions
Imports System.Collections

<Serializable()> Public Class MailslotPermission
    Inherits ResourcePermissionBase

    Private innerCollection As ArrayList


    Public Sub New()
        SetNames()
    End Sub 'New


    Public Sub New(ByVal state As PermissionState)
        MyBase.New(state)
        SetNames()
    End Sub 'New


    Public Sub New(ByVal permissionAccess As MailslotPermissionAccess, ByVal name As String, ByVal machineName1 As String)
        SetNames()
        Me.AddPermissionAccess(New MailslotPermissionEntry(permissionAccess, name, machineName1))
    End Sub 'New


    Public Sub New(ByVal permissionAccessEntries() As MailslotPermissionEntry)
        SetNames()
        If permissionAccessEntries Is Nothing Then
            Throw New ArgumentNullException("permissionAccessEntries")
        End If
        Dim index As Integer

        While index < permissionAccessEntries.Length
            Me.AddPermissionAccess(permissionAccessEntries(index))
        End While
    End Sub 'New 

    Public ReadOnly Property PermissionEntries() As ArrayList
        Get
            If Me.innerCollection Is Nothing Then
                Me.innerCollection = New ArrayList()
            End If
            Me.innerCollection.InsertRange(0, MyBase.GetPermissionEntries())

            Return Me.innerCollection
        End Get
    End Property


    Friend Overloads Sub AddPermissionAccess(ByVal entry As MailslotPermissionEntry)
        MyBase.AddPermissionAccess(entry.GetBaseEntry())
    End Sub 'AddPermissionAccess


    Friend Shadows Sub Clear()
        MyBase.Clear()
    End Sub 'Clear


    Friend Overloads Sub RemovePermissionAccess(ByVal entry As MailslotPermissionEntry)
        MyBase.RemovePermissionAccess(entry.GetBaseEntry())
    End Sub 'RemovePermissionAccess


    Private Sub SetNames()
        Me.PermissionAccessType = GetType(MailslotPermissionAccess)
        Me.TagNames = New String() {"Name", "Machine"}
    End Sub 'SetNames
End Class 'MailslotPermission

<Flags()> Public Enum MailslotPermissionAccess
    None = 0
    Send = 2
    Receive = 4 Or Send
End Enum 'MailslotPermissionAccess

<Serializable()> Public Class MailslotPermissionEntry
    Private nameVar As String
    Private machineNameVar As String
    Private permissionAccessVar As MailslotPermissionAccess


    Public Sub New(ByVal permissionAccess As MailslotPermissionAccess, ByVal name As String, ByVal machineName1 As String)
        Me.permissionAccessVar = permissionAccess
        Me.nameVar = name
        Me.machineNameVar = machineName1
    End Sub 'New


    Friend Sub New(ByVal baseEntry As ResourcePermissionBaseEntry)
        Me.permissionAccessVar = CType(baseEntry.PermissionAccess, MailslotPermissionAccess)
        Me.nameVar = baseEntry.PermissionAccessPath(0)
        Me.machineNameVar = baseEntry.PermissionAccessPath(1)
    End Sub 'New


    Public ReadOnly Property Name() As String
        Get
            Return Me.nameVar
        End Get
    End Property


    Public ReadOnly Property MachineName() As String
        Get
            Return Me.machineNameVar
        End Get
    End Property


    Public ReadOnly Property PermissionAccess() As MailslotPermissionAccess
        Get
            Return Me.permissionAccessVar
        End Get
    End Property


    Friend Function GetBaseEntry() As ResourcePermissionBaseEntry
        Dim baseEntry As New ResourcePermissionBaseEntry(CInt(Me.PermissionAccess), New String() {Me.Name, Me.MachineName})
        Return baseEntry
    End Function 'GetBaseEntry


End Class 'MailslotPermissionEntry

[C#] 
using System;        
using System.Security.Permissions;  
using System.Collections;

[Serializable()]
public class MailslotPermission: ResourcePermissionBase
{
 
    private ArrayList innerCollection;

    public MailslotPermission() 
    {
        SetNames();
    }                                                                

    public MailslotPermission(PermissionState state):base(state)
    {
        SetNames();
    }  

    public MailslotPermission(MailslotPermissionAccess permissionAccess, string name, string machineName)
    {
        SetNames();
        this.AddPermissionAccess(new MailslotPermissionEntry(permissionAccess, name, machineName));              
    }

    public MailslotPermission(MailslotPermissionEntry[] permissionAccessEntries) 
    {
        SetNames();
        if (permissionAccessEntries == null)
            throw new ArgumentNullException("permissionAccessEntries");
      
        for (int index = 0; index < permissionAccessEntries.Length; ++index)
            this.AddPermissionAccess(permissionAccessEntries[index]);                          
    }

    public ArrayList PermissionEntries 
    {
        get 
        {
            if (this.innerCollection == null)                     
                this.innerCollection = new ArrayList();
            this.innerCollection.InsertRange(0,base.GetPermissionEntries()); 

            return this.innerCollection;                                                               
        }
    }

    internal void AddPermissionAccess(MailslotPermissionEntry entry) 
    {
        base.AddPermissionAccess(entry.GetBaseEntry());
    }

    internal new void Clear() 
    {
        base.Clear();
    }

    internal void RemovePermissionAccess(MailslotPermissionEntry entry) 
    {
        base.RemovePermissionAccess(entry.GetBaseEntry());
    }

    private void SetNames() 
    {
        this.PermissionAccessType = typeof(MailslotPermissionAccess);
        this.TagNames = new string[]{"Name","Machine"};
    }                                
}

[Flags]         
public enum MailslotPermissionAccess 
{
    None = 0,
    Send = 1 << 1,
    Receive = 1 << 2 | Send,
} 

[Serializable()]     
public class MailslotPermissionEntry 
{
    private string name;
    private string machineName;
    private MailslotPermissionAccess permissionAccess;

    public MailslotPermissionEntry(MailslotPermissionAccess permissionAccess, string name, string machineName) 
    {
        this.permissionAccess = permissionAccess;
        this.name = name;
        this.machineName = machineName;
    }  

    internal MailslotPermissionEntry(ResourcePermissionBaseEntry baseEntry) 
    {
        this.permissionAccess = (MailslotPermissionAccess)baseEntry.PermissionAccess;
        this.name = baseEntry.PermissionAccessPath[0]; 
        this.machineName = baseEntry.PermissionAccessPath[1]; 
    }

    public string Name 
    {
        get 
        {                
            return this.name;                
        }                        
    }

    public string MachineName 
    {
        get 
        {                
            return this.machineName;                
        }                        
    }

    public MailslotPermissionAccess PermissionAccess 
    {
        get 
        {
            return this.permissionAccess;
        }                        
    }      

    internal ResourcePermissionBaseEntry GetBaseEntry() 
    {
        ResourcePermissionBaseEntry baseEntry = new ResourcePermissionBaseEntry((int)this.PermissionAccess, new string[] {this.Name,this.MachineName});            
        return baseEntry;
    }

}

[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Security::Permissions;
using namespace System::Collections;

[Flags]
public __value enum MailslotPermissionAccess {
    None = 0,
    Send = 1 << 1,
    Receive = 1 << 2 | Send,
};

[Serializable]
public __gc class MailslotPermissionEntry {
private:
    String* name;
    String* machineName;
    MailslotPermissionAccess permissionAccess;

public private:
    MailslotPermissionEntry(ResourcePermissionBaseEntry* baseEntry) {
        this->permissionAccess = (MailslotPermissionAccess)baseEntry->PermissionAccess;
        this->name = baseEntry->PermissionAccessPath->Item[0]->ToString();
        this->machineName = baseEntry->PermissionAccessPath->Item[1]->ToString();
    }

    ResourcePermissionBaseEntry* GetBaseEntry() {
        String* newStrings[] = {this->Name, this->MachineName};
        ResourcePermissionBaseEntry* baseEntry = 
            new ResourcePermissionBaseEntry((int)(this->PermissionAccess), newStrings);
        return baseEntry;
    }

public:
    MailslotPermissionEntry(MailslotPermissionAccess permissionAccess, String* name, String* machineName) {
        this->permissionAccess = permissionAccess;
        this->name = name;
        this->machineName = machineName;
    }

    __property String* get_Name() {
        return this->name;
    }

    __property String* get_MachineName() {
        return this->machineName;
    }

    __property MailslotPermissionAccess get_PermissionAccess() {
        return this->permissionAccess;
    }
};

[Serializable]
public __gc class MailslotPermission : public ResourcePermissionBase {
private:
    ArrayList* innerCollection;

    void SetNames() {
        this->PermissionAccessType = __typeof(MailslotPermissionAccess);
        String* newStrings[] = {S"Name", S"Machine"};
        this->TagNames = newStrings;
    }

public private:
    void AddPermissionAccess(MailslotPermissionEntry* entry) {
        ResourcePermissionBase::AddPermissionAccess(entry->GetBaseEntry());
    }

    void Clear() {
        ResourcePermissionBase::Clear();
    }

    void RemovePermissionAccess(MailslotPermissionEntry* entry) {
        ResourcePermissionBase::RemovePermissionAccess(entry->GetBaseEntry());
    }

public:
    MailslotPermission() {
        SetNames();
    }

    MailslotPermission(PermissionState state) : ResourcePermissionBase(state) {
        SetNames();
    }

    MailslotPermission(MailslotPermissionAccess permissionAccess, String* name, String* machineName) {
        SetNames();
        this->AddPermissionAccess(new MailslotPermissionEntry(permissionAccess, name, machineName));
    }

    MailslotPermission(MailslotPermissionEntry* permissionAccessEntries[]) {
        SetNames();
        if (permissionAccessEntries == 0)
            throw new ArgumentNullException(S"permissionAccessEntries");

        for (int index = 0; index < permissionAccessEntries->Length; ++index)
            this->AddPermissionAccess(permissionAccessEntries[index]);
    }

    __property ArrayList* get_PermissionEntries() {
        if (this->innerCollection == 0)
            this->innerCollection = new ArrayList();
        this->innerCollection->InsertRange(0, __try_cast<ICollection*>(ResourcePermissionBase::GetPermissionEntries()));

        return this->innerCollection;
    }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Security.Permissions

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System (System.dll 内)

参照

ResourcePermissionBase メンバ | System.Security.Permissions 名前空間