devxlogo

FilterByName – filtering by name the results of Type.FindMembers

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

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist