MethodBuilder.AddDeclarativeSecurity メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MethodBuilder.AddDeclarativeSecurity メソッドの意味・解説 

MethodBuilder.AddDeclarativeSecurity メソッド

このメソッドに宣言セキュリティを追加します。

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub AddDeclarativeSecurity ( _
    action As SecurityAction, _
    pset As PermissionSet _
)
Dim instance As MethodBuilder
Dim action As SecurityAction
Dim pset As PermissionSet

instance.AddDeclarativeSecurity(action, pset)
public void AddDeclarativeSecurity (
    SecurityAction action,
    PermissionSet pset
)
public:
void AddDeclarativeSecurity (
    SecurityAction action, 
    PermissionSet^ pset
)
public void AddDeclarativeSecurity (
    SecurityAction action, 
    PermissionSet pset
)
public function AddDeclarativeSecurity (
    action : SecurityAction, 
    pset : PermissionSet
)

パラメータ

action

実行するセキュリティ アクション (Demand、Assert など)。

pset

アクションが適用する一連のアクセス許可。

例外例外
例外の種類条件

ArgumentOutOfRangeException

action が無効です。RequestMinimum、RequestOptional、および RequestRefuse が無効です。

InvalidOperationException

外側の型が CreateType を使用して作成されています。

または

アクセス許可セット pset に、既に AddDeclarativeSecurity によって追加されたアクションが含まれています。

または

現在のメソッドでは、IsGenericMethod プロパティは true ですが、IsGenericMethodDefinition プロパティが false です。

ArgumentNullException

pset が null 参照 (Visual Basic では Nothing) です。

使用例使用例

AddDeclarativeSecurity を使用して、無制限のアクセス許可をメソッドの呼び出し元に対して要求する方法については、次のコード例を参照してください。

' myModBuilder is an instance of ModuleBuilder.
' Note that for the use of PermissionSet and SecurityAction,
' the namespaces System.Security and System.Security.Permissions
' should be included.
Dim myTypeBuilder As TypeBuilder = myModBuilder.DefineType("MyType",
 _
                        TypeAttributes.Public)

Dim myMethod1 As MethodBuilder = myTypeBuilder.DefineMethod("MyMethod",
 _
                       MethodAttributes.Public, _
                       GetType(Integer), _
                       New Type() {GetType(Integer),
 GetType(Integer)})

Dim myMethodPermissions As New
 PermissionSet(PermissionState.Unrestricted)

myMethod1.AddDeclarativeSecurity(SecurityAction.Demand, myMethodPermissions)

// myModBuilder is an instance of ModuleBuilder.
// Note that for the use of PermissionSet and SecurityAction,
// the namespaces System.Security and System.Security.Permissions
// should be included.

TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyType",
                    TypeAttributes.Public);

                    
MethodBuilder myMethod1 = myTypeBuilder.DefineMethod("MyMethod",
                    MethodAttributes.Public, 
                    typeof(int),
                    new Type[] 
                    {typeof(int), typeof(int)});
    

PermissionSet myMethodPermissions = new PermissionSet(
            PermissionState.Unrestricted);

myMethod1.AddDeclarativeSecurity(SecurityAction.Demand,
                 myMethodPermissions);

// myModBuilder is an instance of ModuleBuilder.
// Note that for the use of PermissionSet and SecurityAction,
// the namespaces System::Security and System::Security::Permissions
// should be included.

TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "MyType",
                             TypeAttributes::Public );

array<Type^>^ temp0 = {int::typeid, int::typeid};
MethodBuilder^ myMethod1 = myTypeBuilder->DefineMethod( "MyMethod",
                           MethodAttributes::Public,
                           int::typeid, temp0 );

PermissionSet^ myMethodPermissions = gcnew PermissionSet(
                                     PermissionState::Unrestricted );

myMethod1->AddDeclarativeSecurity( SecurityAction::Demand,
                                   myMethodPermissions );
// myModBuilder is an instance of ModuleBuilder.
// Note that for the use of PermissionSet and SecurityAction,
// the namespaces System.Security and System.Security.Permissions
// should be included.
TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyType",
    TypeAttributes.Public);
MethodBuilder myMethod1 = myTypeBuilder.DefineMethod("MyMethod",
    MethodAttributes.Public,int.class.ToType()
,
    new Type[] { int.class.ToType(),
 int.class.ToType() });
PermissionSet myMethodPermissions =
    new PermissionSet(PermissionState.Unrestricted);
myMethod1.AddDeclarativeSecurity(SecurityAction.Demand,
    myMethodPermissions);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MethodBuilder クラス
MethodBuilder メンバ
System.Reflection.Emit 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

MethodBuilder.AddDeclarativeSecurity メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MethodBuilder.AddDeclarativeSecurity メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS