[Mono-devel-list] Type.FilterName Fix
Rafael Teixeira
monoman at gmail.com
Wed Jan 19 08:05:33 EST 2005
Well now this is a patch to solve the problem, amassad from all
suggestions in this thread, and taking care of the case-insensitive
method too, as it also has the same behaviour...
------------------------------
Index: Type.cs
===================================================================
--- Type.cs (revision 39146)
+++ Type.cs (working copy)
@@ -59,16 +59,25 @@
static bool FilterName_impl (MemberInfo m, object
filterCriteria)
{
string name = (string) filterCriteria;
- return name.Equals (m.Name);
+ if (name == null || name.Length == 0 )
+ return false; // because m.Name cannot
be null or empty
+
+ if (name [name.Length-1] == '*')
+ return string.Compare (name, 0,
m.Name, 0, name.Length-1, false, CultureInfo.InvariantCulture) == 0;
+
+ return name.Equals (m.Name);
}
static bool FilterNameIgnoreCase_impl (MemberInfo m,
object filterCriteria)
{
string name = (string) filterCriteria;
- if (name.Length != m.Name.Length)
- return false;
+ if (name == null || name.Length == 0 )
+ return false; // because m.Name cannot
be null or empty
+
+ if (name [name.Length-1] == '*')
+ return string.Compare (name, 0,
m.Name, 0, name.Length-1, true, CultureInfo.InvariantCulture) == 0;
- return String.Compare (name, m.Name, true,
CultureInfo.InvariantCulture) == 0;
+ return String.Compare (name, m.Name, true,
CultureInfo.InvariantCulture) == 0;
}
static bool FilterAttribute_impl (MemberInfo m, object
filterCriteria)
------------------------------
Can I commit?
On Wed, 19 Jan 2005 07:15:34 -0500, Jonathan Pryor <jonpryor at vt.edu> wrote:
> On Wed, 2005-01-19 at 03:28 +0100, Willibald Krenn wrote:
> > However, just as a quick hack:
> >
> > int filterLen = name.Length;
> > if (name [filterLen] != "*")
> > return name.Equals(m.Name);
> > else
> > return String.Compare (name, 0, m.Name, 0, filterLen-1, false,
> > CultureInfo.InvariantCulture) == 0;
>
> The problem with quick hacks is that they can be wrong. :-)
>
> There's an off-by-one error: it should be ``name [filterLen-1] != '*'''.
> And if the string is an empty string, you'll get an exception, so it
> should really be:
>
> if (name != null && name.Length > 0 &&
> name [name.Length-1] != '*')
> return name.Equals (m.Name);
> return string.Compare (name, 0, m.Name, 0, name.Length-1, false,
> CultureInfo.InvariantCulture) == 0;
>
> And it may *still* be wrong (since I haven't actually tested it yet).
>
> :-)
>
> - Jon
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
--
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes.
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
More information about the Mono-devel-list
mailing list