[Mono-devel-list] Type.FilterName Fix

Ben Maurer bmaurer at ximian.com
Tue Jan 18 21:14:08 EST 2005


On Wed, 2005-01-19 at 03:07 +0100, Willibald Krenn wrote:
> 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;
> }

String.Compare is going to be much slower than String.Equals, so you
should use the .Equals for the default case.

(Also, you should probably use name [len - 1] == '*', because EndsWith
does culture type crap)

-- Ben




More information about the Mono-devel-list mailing list