Problem with factory methods and "'Public Default Property Item"

Problem with factory methods and "'Public Default Property Item"

Old forum URL: forums.lhotka.net/forums/t/8122.aspx


cmay posted on Wednesday, December 09, 2009

I've just run into a problem that I am trying to figure out.

I have a list class. You can get an instance of it with GetList() or you can supply a filter which in turn is passed to the database, by using GetList("search string").

The problem is that if I didn't have the 2nd method, you could still say GetList(3) , and it would give you the 4th item in that list, basically doing GetList()(3) because "Item" is set as a default property.

So, if I try to call GetList("my string") it breaks at runtime (compile time, everything is great, and intellisense sees that I'm calling the 2nd method), but at runtime it just assumes I'm doing GetList()("My string") which of course doesn't work.

I know I could rename all "Get" methods that take a parameter, which is what I'll have to do in the short term, but is there any solution to this that anyone knows?

I didn't find any way that I could "undo" or change the default property on the list.

Copyright (c) Marimer LLC