DefaultMemberAttribute クラス
InvokeMember が使用する既定のメンバである型のメンバを定義します。既定のメンバは、型に与えられている名前です。
この型のすべてのメンバの一覧については、DefaultMemberAttribute メンバ を参照してください。
System.Object
System.Attribute
System.Reflection.DefaultMemberAttribute
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Struct _
Or AttributeTargets.Interface)>
<Serializable>
NotInheritable Public Class DefaultMemberAttribute Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Interface)]
[Serializable]
public sealed class DefaultMemberAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Class | AttributeTargets::Struct
| AttributeTargets::Interface)]
[Serializable]
public __gc __sealed class DefaultMemberAttribute : public Attribute
[JScript]
public
AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Interface)
Serializable
class DefaultMemberAttribute extends Attribute
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
使用例
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]
[C#]
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);
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::IO;
[DefaultMemberAttribute(S"Age")]
public __gc class MyClass {
public:
void Name(String* s) {}
__property int get_Age() {
return 20;
}
};
int main() {
try {
Type* myType = __typeof(MyClass);
MemberInfo* memberInfoArray[] = myType->GetDefaultMembers();
if (memberInfoArray->Length > 0) {
System::Collections::IEnumerator* myEnum = memberInfoArray->GetEnumerator();
while (myEnum->MoveNext()) {
MemberInfo* memberInfoObj = __try_cast<MemberInfo*>(myEnum->Current);
Console::WriteLine(S"The default member name is: {0}", memberInfoObj);
}
} else {
Console::WriteLine(S"No default members are available.");
}
} catch (InvalidOperationException* e) {
Console::WriteLine(S"InvalidOperationException: {0}", e->Message);
} catch (IOException* e) {
Console::WriteLine(S"IOException: {0}", e->Message);
} catch (Exception* e) {
Console::WriteLine(S"Exception: {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Reflection
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
アセンブリ: Mscorlib (Mscorlib.dll 内)