ConstructorBuilder.DeclaringType プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ConstructorBuilder.DeclaringType プロパティの意味・解説 

ConstructorBuilder.DeclaringType プロパティ

このメンバ宣言する型の Type オブジェクトへの参照取得します

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

Public Overrides ReadOnly
 Property DeclaringType As Type
Dim instance As ConstructorBuilder
Dim value As Type

value = instance.DeclaringType
public override Type DeclaringType { get; }
public:
virtual property Type^ DeclaringType {
    Type^ get () override;
}
/** @property */
public Type get_DeclaringType ()

プロパティ
このメンバ宣言する型の Type オブジェクト返します

解説解説

クラス (またはインターフェイス) のメンバは、宣言されるか、基本クラス (またはインターフェイス) から継承されます。

DeclaringType使用方法については、次のコード例参照してください

Dim myMethodBuilder As MethodBuilder = Nothing

Dim myCurrentDomain As AppDomain = AppDomain.CurrentDomain
' Create assembly in current CurrentDomain
Dim myAssemblyName As New
 AssemblyName()
myAssemblyName.Name = "TempAssembly"
' Create a dynamic assembly
myAssemblyBuilder = _
      myCurrentDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.RunAndSave)
' Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")
Dim myFieldInfo As FieldInfo = _
    myModuleBuilder.DefineUninitializedData("myField",
 2, FieldAttributes.Public)
' Create a type in the module
Dim myTypeBuilder As TypeBuilder = _
    myModuleBuilder.DefineType("TempClass", TypeAttributes.Public)
Dim myGreetingField As FieldBuilder = _
   myTypeBuilder.DefineField("Greeting", GetType(String),
 FieldAttributes.Public)
Dim myConstructorArgs As Type() = {GetType(String)}
' Define a constructor of the dynamic class.
Dim myConstructor As ConstructorBuilder = _
    myTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard,
 _
                                    myConstructorArgs)
Dim myPset As New PermissionSet(PermissionState.Unrestricted)
' Add declarative security to the constructor.
Console.WriteLine("Adding declarative security to the constructor.....")
Console.WriteLine("The Security action to be taken is ""DENY""
 and" + _
                  " Permission set is ""UNRESTRICTED"".")
myConstructor.AddDeclarativeSecurity(SecurityAction.Deny, myPset)
Dim myMethodAttributes As MethodAttributes
 = myConstructor.Attributes
Dim myAttributeType As Type = GetType(MethodAttributes)
Dim myAttribValue As Integer
 = CInt(myMethodAttributes)
If Not myAttributeType.IsEnum Then
   Console.WriteLine("This is not an Enum")
End If
Dim myFieldInfo1 As FieldInfo() = myAttributeType.GetFields(BindingFlags.Public
 Or _
                                                             BindingFlags.Static)
Console.WriteLine("The Field info names of the Attributes for
 the constructor are:")
Dim i As Integer
For i = 0 To myFieldInfo1.Length - 1
   Dim myFieldValue As Integer
 = CType(myFieldInfo1(i).GetValue(Nothing), Int32)
   If(myFieldValue And myAttribValue) = myFieldValue
 Then
      Console.WriteLine("   " + myFieldInfo1(i).Name)
   End If
Next i

Dim myType2 As Type = myConstructor.DeclaringType
Console.WriteLine("The declaring type is : " + myType2.ToString())
MethodBuilder myMethodBuilder=null;

AppDomain myCurrentDomain = AppDomain.CurrentDomain;
// Create assembly in current CurrentDomain
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Create a dynamic assembly
myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly
   (myAssemblyName, AssemblyBuilderAccess.RunAndSave);
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");
FieldInfo myFieldInfo =
   myModuleBuilder.DefineUninitializedData("myField",2,FieldAttributes.Public);
// Create a type in the module
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("TempClass",TypeAttributes.Public);
FieldBuilder myGreetingField = myTypeBuilder.DefineField("Greeting",
   typeof(String), FieldAttributes.Public);
Type[] myConstructorArgs = { typeof(String) };
// Define a constructor of the dynamic class.
ConstructorBuilder myConstructor = myTypeBuilder.DefineConstructor(
   MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs);
PermissionSet myPset = new PermissionSet(PermissionState.Unrestricted);
// Add declarative security to the constructor.
Console.WriteLine("Adding declarative security to the constructor.....");
Console.WriteLine("The Security action to be taken is \"DENY\" and"
 +
   " Permission set is \"UNRESTRICTED\".");
myConstructor.AddDeclarativeSecurity(SecurityAction.Deny,myPset);
MethodAttributes myMethodAttributes = myConstructor.Attributes;
Type myAttributeType = typeof(MethodAttributes);
int myAttribValue = (int) myMethodAttributes;
if(! myAttributeType.IsEnum)
{
   Console.WriteLine("This is not an Enum");
}
FieldInfo[] myFieldInfo1 = myAttributeType.GetFields(BindingFlags.Public | BindingFlags.Static);
Console.WriteLine("The Field info names of the Attributes for
 the constructor are:");
for (int i = 0; i < myFieldInfo1.Length;
 i++)
{
   int myFieldValue = (Int32)myFieldInfo1[i].GetValue(null);
   if ((myFieldValue & myAttribValue) == myFieldValue)
   {
      Console.WriteLine("   " + myFieldInfo1[i].Name);
   }
}

Type myType2 = myConstructor.DeclaringType;
Console.WriteLine("The declaring type is : "+myType2.ToString());
MethodBuilder^ myMethodBuilder = nullptr;

AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
// Create assembly in current CurrentDomain
AssemblyName^ myAssemblyName = gcnew AssemblyName;
myAssemblyName->Name = "TempAssembly";
// Create a dynamic assembly
myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly(
   myAssemblyName, AssemblyBuilderAccess::RunAndSave );
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule"
 );
FieldInfo^ myFieldInfo =
   myModuleBuilder->DefineUninitializedData( "myField", 2, FieldAttributes::Public
 );
// Create a type in the module
TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass",
 TypeAttributes::Public );
FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting"
,
   String::typeid, FieldAttributes::Public );
array<Type^>^myConstructorArgs = {String::typeid};
// Define a constructor of the dynamic class.
ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor(
   MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
PermissionSet^ myPset = gcnew PermissionSet( PermissionState::Unrestricted );
// Add declarative security to the constructor.
Console::WriteLine( "Adding declarative security to the constructor....."
 );
Console::WriteLine( "The Security action to be taken is \"DENY\" and"
 +
   " Permission set is \"UNRESTRICTED\"."
 );
myConstructor->AddDeclarativeSecurity( SecurityAction::Deny, myPset );
MethodAttributes myMethodAttributes = myConstructor->Attributes;
Type^ myAttributeType = MethodAttributes::typeid;
int myAttribValue = (int)myMethodAttributes;
if (  !myAttributeType->IsEnum )
{
   Console::WriteLine( "This is not an Enum" );
}
array<FieldInfo^>^myFieldInfo1 = myAttributeType->GetFields( static_cast<BindingFlags>(BindingFlags::Public
 | BindingFlags::Static) );
Console::WriteLine( "The Field info names of the Attributes for
 the constructor are:" );
for ( int i = 0; i < myFieldInfo1->Length;
 i++ )
{
   int myFieldValue =  *dynamic_cast<Int32^>(myFieldInfo1[
 i ]->GetValue( nullptr ));
   if ( (myFieldValue & myAttribValue) == myFieldValue )
   {
      Console::WriteLine( "   {0}", myFieldInfo1[ i ]->Name );
   }
}

Type^ myType2 = myConstructor->DeclaringType;
Console::WriteLine( "The declaring type is : {0}", myType2 );
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConstructorBuilder クラス
ConstructorBuilder メンバ
System.Reflection.Emit 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からConstructorBuilder.DeclaringType プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConstructorBuilder.DeclaringType プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConstructorBuilder.DeclaringType プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ConstructorBuilder.DeclaringType プロパティのお隣キーワード
検索ランキング

   

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



ConstructorBuilder.DeclaringType プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS