C# Type GetDefaultMembers

Description

Type GetDefaultMembers searches for the members defined for the current Type whose DefaultMemberAttribute is set.

Syntax

Type.GetDefaultMembers has the following syntax.


public virtual MemberInfo[] GetDefaultMembers()

Returns

Type.GetDefaultMembers method returns

Example

The following example obtains the default member information of MyClass and displays the default members.


/*from ww w.j  a v  a  2 s.co m*/
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()
    {
        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."); 
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version