Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Nov 4, 2002

FilterByName - filtering by name the results of Type.FindMembers

' This filtering function returns True if the member name 
' begins with the character passed as its second argument.
' Note: it requires Imports System.Reflection
Function FilterByName(ByVal m As MemberInfo, ByVal filterCriteria As Object) As _
    Boolean
    If m.Name.StartsWith(filterCriteria.ToString) Then
        Return True
    End If
End Function


' EXAMPLE:
' Get a reference to the System.String type.
Dim stringType As Type = Type.GetType("System.String")
Dim minfos() As MemberInfo

' Get only public, instance methods and properties
' whose name begins with "C".
minfos = stringType.FindMembers(MemberTypes.Method Or MemberTypes.Property, _
    BindingFlags.Public Or BindingFlags.Instance, AddressOf FilterByName, "C")

' List the results.
Dim mi As MemberInfo
For Each mi In minfos
    Debug.WriteLine(mi.Name)
Next


' Note: This code is taken from Francesco Balena's
' "Programming Microsoft Visual Basic .NET" - MS Press 2002, ISBN 0735613753
' You can read a free chapter of the book at 
' http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=101000
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap