non generic DataPortal exception bug?

non generic DataPortal exception bug?

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


rfcdejong posted on Friday, July 24, 2009

Someone at my company was using

DataPortal.Delete(SingleCriteria<T, C> foobar);

And it worked as expected :)
But somewhere else at his learningcurve he made a own criteria class derived from CriteriaBase which he uses for several situations in multiple business objects. Then he wrote:

DataPortal.Delete(new MyCriteriaClass(param1, param2));

He kinda forgot to use the generic DataPortal.
He got an ArgumentNullException "Value cannot be null. Parameter name: key" at the DataPortal. That is because the CriteriaClass didn't return an objecttype.


I would like an better exception when the criteria class does not provide an type (the generic DataPortal should be used?)

public static void Delete(object criteria)
{
      Type objectType = MethodCaller.GetObjectType(criteria);
      Delete(objectType, criteria);
}

ajj3085 replied on Friday, July 24, 2009

MyCriteriaClass should be inheriting CriteriaBase, and it should be calling the constructor and giving it the type there. That's typically what I do, but maybe its not required if you simply add the type between the end of the method name and the opening (.

DataPortal.Delete&lt;T&gt;( new MyCriteriaClass )

rfcdejong replied on Monday, August 10, 2009

ajj3085:
MyCriteriaClass should be inheriting CriteriaBase, and it should be calling the constructor and giving it the type there. That's typically what I do, but maybe its not required if you simply add the type between the end of the method name and the opening (.

DataPortal.Delete( new MyCriteriaClass )


Yes a generic along with it, but if u forget it then there is a invalid value exception which is not clear on what the programmer did wrong.

I would like to see this as a bug, to raise an exception in run time telling the programmer might had forgotten the generic type argument.

PS: I've been on vacation so this post is a bit late.

Copyright (c) Marimer LLC