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

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ <AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Interface)> _ Public NotInheritable Class DefaultMemberAttribute Inherits Attribute
[SerializableAttribute] [ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface)] public sealed class DefaultMemberAttribute : Attribute
[SerializableAttribute] [ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Interface)] public ref class DefaultMemberAttribute sealed : public Attribute

プロパティは、そのプロパティに引数が存在し、かつ、プロパティ名またはそのいずれかのアクセサが DefaultMemberAttribute で指定された名前と一致する場合、インデクサ (Visual Basic では既定のインデックス付きプロパティ) としてインポートされます。格納している型に DefaultMemberAttribute が存在しない場合、その型にはインデクサは存在しません。C# コンパイラでは、インデクサを含むすべての型について、DefaultMemberAttribute を出力します。C# では、既にインデクサが宣言されている型に対し、直接 DefaultMemberAttribute で属性を指定するとエラーになります。

Imports System Imports System.Reflection Imports System.IO Imports Microsoft.VisualBasic <DefaultMemberAttribute("Age")> Public Class [MyClass] Public Sub Name(ByVal s As String) End Sub 'Name Public ReadOnly Property Age() As Integer Get Return 20 End Get End Property Public Shared Sub Main() Try Dim myType As Type = GetType([MyClass]) Dim memberInfoArray As MemberInfo() = myType.GetDefaultMembers() If memberInfoArray.Length > 0 Then Dim memberInfoObj As MemberInfo For Each memberInfoObj In memberInfoArray Console.WriteLine("The default member name is: " + memberInfoObj.ToString()) Next memberInfoObj Else Console.WriteLine("No default members are available.") End If Catch e As InvalidOperationException Console.WriteLine("InvalidOperationException: " + e.Message) Catch e As IOException Console.WriteLine("IOException: " + e.Message) Catch e As Exception Console.WriteLine("Exception: " + e.Message) End Try End Sub 'Main End Class '[MyClass]
using System; using System.Reflection; using System.IO; [DefaultMemberAttribute("Age")] public class MyClass { public void Name(String s) {} public int Age { get { return 20; } } public static void Main() { try { Type myType = typeof(MyClass); MemberInfo[] memberInfoArray = myType.GetDefaultMembers(); if (memberInfoArray.Length > 0) { foreach(MemberInfo memberInfoObj in memberInfoArray) { Console.WriteLine("The default member name is: " + memberInfoObj.ToString()); } } else { Console.WriteLine("No default members are available."); } } catch(InvalidOperationException e) { Console.WriteLine("InvalidOperationException: " + e.Message); } catch(IOException e) { Console.WriteLine("IOException: " + e.Message); } catch(Exception e) { Console.WriteLine("Exception: " + e.Message); } } }
using namespace System; using namespace System::Reflection; using namespace System::IO; [DefaultMemberAttribute("Age")] public ref class MyClass { public: void Name( String^ s ){} property int Age { int get() { return 20; } } }; int main() { try { Type^ myType = MyClass::typeid; array<MemberInfo^>^memberInfoArray = myType->GetDefaultMembers(); if ( memberInfoArray->Length > 0 ) { System::Collections::IEnumerator^ myEnum = memberInfoArray->GetEnumerator(); while ( myEnum->MoveNext() ) { MemberInfo^ memberInfoObj = safe_cast<MemberInfo^>(myEnum->Current); Console::WriteLine( "The default member name is: {0}", memberInfoObj ); } } else { Console::WriteLine( "No default members are available." ); } } catch ( InvalidOperationException^ e ) { Console::WriteLine( "InvalidOperationException: {0}", e->Message ); } catch ( IOException^ e ) { Console::WriteLine( "IOException: {0}", e->Message ); } catch ( Exception^ e ) { Console::WriteLine( "Exception: {0}", e->Message ); } }
import System.*; import System.Reflection.*; import System.IO.*; /** @attribute DefaultMemberAttribute("Age") */ public class MyClass { public void Name(String s) { } //Name /** @property */ public int get_Age() { return 20; } //get_Age public static void main(String[] args) { try { Type myType = MyClass.class.ToType(); MemberInfo memberInfoArray[] = myType.GetDefaultMembers(); if (memberInfoArray.length > 0) { for (int iCtr = 0; iCtr < memberInfoArray.length; iCtr++) { MemberInfo memberInfoObj = memberInfoArray[iCtr]; Console.WriteLine("The default member name is: " + memberInfoObj.ToString()); } } else { Console.WriteLine("No default members are available."); } } catch (InvalidOperationException e) { Console.WriteLine("InvalidOperationException: " + e.get_Message()); } catch (IOException e) { Console.WriteLine("IOException: " + e.get_Message()); } catch (System.Exception e) { Console.WriteLine("Exception: " + e.get_Message()); } } //main } //MyClass

System.Attribute
System.Reflection.DefaultMemberAttribute


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DefaultMemberAttribute コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DefaultMemberAttribute プロパティ
DefaultMemberAttribute メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

DefaultMemberAttribute メンバ
InvokeMember が使用する既定のメンバである型のメンバを定義します。
DefaultMemberAttribute データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

- DefaultMemberAttributeのページへのリンク