CodeAccessSecurityAttribute クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ <AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Constructor Or AttributeTargets.Method, AllowMultiple:=True, Inherited:=False)> _ Public MustInherit Class CodeAccessSecurityAttribute Inherits SecurityAttribute
[SerializableAttribute] [ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false)] public abstract class CodeAccessSecurityAttribute : SecurityAttribute
[SerializableAttribute] [ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Constructor|AttributeTargets::Method, AllowMultiple=true, Inherited=false)] public ref class CodeAccessSecurityAttribute abstract : public SecurityAttribute
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ /** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) */ public abstract class CodeAccessSecurityAttribute extends SecurityAttribute
SerializableAttribute ComVisibleAttribute(true) AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) public abstract class CodeAccessSecurityAttribute extends SecurityAttribute

この属性クラスは、Demand などの SecurityAction をカスタム セキュリティ属性に関連付けます。
CodeAccessSecurityAttribute から派生する型は、リソースやセキュリティ設定可能な操作へのアクセスを制限するために使用されます。
セキュリティ属性によって宣言されたセキュリティ情報は、属性ターゲットのメタデータに格納され、実行時にシステムによってアクセスされます。セキュリティ属性は宣言セキュリティにだけ使用されます。強制セキュリティの場合は、CodeAccessPermission から派生した、対応するアクセス許可クラスを使用します。
継承時の注意 このクラスから派生させるアクセス許可属性にはすべて、SecurityAction を唯一のパラメータとして受け取るコンストラクタを必ず 1 つだけ定義してください。
CodeAccessSecurityAttribute クラスから派生したアクセス許可属性の例を次に示します。
Imports System Imports System.IO Imports System.Runtime.Remoting Imports System.Security Imports System.Security.Permissions Imports System.Reflection Imports MyPermission Imports Microsoft.VisualBasic ' Use the command line option '/keyfile' or appropriate project settings to sign this assembly. <Assembly: System.Security.AllowPartiallyTrustedCallersAttribute()> Namespace MyPermissionAttribute <AttributeUsage(AttributeTargets.All, AllowMultiple:=True, Inherited:=False)> Public NotInheritable Class NameIdPermissionAttribute Inherits CodeAccessSecurityAttribute Private m_Name As String = Nothing Private m_unrestricted As Boolean = False Public Sub New(ByVal action As SecurityAction) MyBase.New(action) End Sub 'New Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Overrides Function CreatePermission() As IPermission If m_unrestricted Then Throw New ArgumentException("Unrestricted permissions not allowed in identity permissions.") Else If m_name Is Nothing Then Return New NameIdPermission(PermissionState.None) End If Return New NameIdPermission(m_name) End If End Function 'CreatePermission End Class ' NameIdPermissionAttribute End Namespace
using System; using System.IO; using System.Runtime.Remoting; using System.Security; using System.Security.Permissions; using System.Reflection; using MyPermission; // Use the command line option '/keyfile' or appropriate project settings to sign this assembly. [assembly: System.Security.AllowPartiallyTrustedCallersAttribute ()] namespace MyPermissionAttribute { [AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)] [Serializable] sealed public class NameIdPermissionAttribute : CodeAccessSecurityAttribute { private String m_Name = null; private bool m_unrestricted = false; public NameIdPermissionAttribute (SecurityAction action): base( action ) { } public String Name { get { return m_Name; } set { m_Name = value; } } public override IPermission CreatePermission () { if (m_unrestricted) { throw new ArgumentException ("Unrestricted permissions not allowed in identity permissions."); } else { if (m_Name == null) return new NameIdPermission (PermissionState.None); return new NameIdPermission (m_Name); } } } }

System.Attribute
System.Security.Permissions.SecurityAttribute
System.Security.Permissions.CodeAccessSecurityAttribute
派生クラス


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CodeAccessSecurityAttribute クラスのページへのリンク