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.ReflectionFunction FilterByName(ByVal m As MemberInfo, ByVal filterCriteria As Object) As _    Boolean    If m.Name.StartsWith(filterCriteria.ToString) Then        Return True    End IfEnd 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 MemberInfoFor 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

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: