Using the DefaultMemberAttribute

The DefaultMemberAttribute is applied to a type and takes a string argument indicating the name of the default member. The default member can be invoked by InvokeMember without passing the name of the member to invoke. For example, if we apply the DefaultMemberAttribute to ReflectedClass, naming the HelloWorld method as the default member, we can invoke HelloWorld without naming the method. Listing 4.7 shows the ReflectedClass class and a call to InvokeMember that relies on the DefaultMemberAttribute.

Listing 4.7. Applying and Invoking a Default Member
 Imports System.Reflection <DefaultMember("HelloWorld")> _ Public Class ReflectedClass Private FMessage As String Public Sub New(ByVal Message As String) FMessage ...

Get Visual Basic® .NET Power Coding now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.