API Hall of Shame #1 - Misleading names

Why does Type.GetMember return an array of members? It's description states:

Gets the specified members of the current Type.

Here's a hint; if you are going to return multiple things from a method or property, give it a plural name - it just makes sense.

Published Saturday, December 06, 2008 7:00 AM by David Kean

Comments

Monday, December 08, 2008 1:33 PM by Popanz A

# re: API Hall of Shame #1 - Misleading names

Type.GetMember returns a single member. Did you notice the name paramter?

What version of Type.GetMember are you looking at? All three overloads (1, 2, 3) return multiple members if their names are the same. For example, if I have three overloaded methods all called 'Foo', it will return all three if I pass 'Foo' as the name parameter.
Monday, December 08, 2008 5:20 PM by Stevi Deter

# re: API Hall of Shame #1 - Misleading names

Now I feel better about taking the time recently to update a method's name to plural because it returned a List. Made me crazy and I finally just had to fix it.

Friday, January 16, 2009 6:46 PM by dand

# re: API Hall of Shame #1 - Misleading names

I agree completely with naming things clearly, i would argue to have the method name to be GetAllMembers().  It might be a small point but 'All' stands out and clearly implies more than one.  "All" stands out textually better than an 's' at the end of a method name. Additionally i've seen a few times intellisense, as helpful as it tries to be, will at times select the wrong/first method from intellisense.   So i would be one to argue to have GetMember() and GetAllMembers().