[Mono-devel-list] Type.FilterName Fix

Willibald Krenn Willibald.Krenn at gmx.at
Tue Jan 18 21:07:30 EST 2005


Hi!

According to MS, Type.FilterName also takes a wildcard as last char:

"This field holds a reference to the delegate used by the FindMembers 
method. The method encapsulated by this delegate takes two parameters: 
the first is a MemberInfo object and the second is an Object. The method 
determines whether the MemberInfo object matches the criteria specified 
by the Object. The Object is assigned a string value, which may include 
a trailing "*" wildcard character. Only wildcard end string matching is 
supported."
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtypeclassfilternametopic.asp


Current Mono FilterName_impl method does not allow wildcard-searches, so 
I've fixed the method (in Type.cs):

/* implementation of the delegates for MemberFilter */
static bool FilterName_impl (MemberInfo m, object filterCriteria)
{
	string name = (string) filterCriteria;
	int filterLen = name.Length;

	/* last char can be '*' */
	if (name.EndsWith ("*"))
		filterLen--;

	return String.Compare (name, 0, m.Name, 0, filterLen, false,
		 CultureInfo.InvariantCulture) == 0;
}

This version will also work for '*' type of filters, because 
String.Compare(..) returns zero too if filterLen is 0.

regards,
  Willi




More information about the Mono-devel-list mailing list