Hi guys,
Was wondering if anybody had the need to create a Generic class of some sort that can handle multiple criterias.
I see CSLA has a singleCriteria class ,and this saves quite a bit of work,however has it crossed anybody's mind to create a class that uses generics that can handle more than one parameters and get a sort strongly typed multicriteria object?
At work we create lot's of criteria's classes and it's quite timeconsuming.
We are not adopting CSLA but i use it for my personal projects.
Again,I thought i would ask the CSLA community as you guys use criteria objects quite a lot.
Thanks again
Brix
Not entirely sure if this would work, but the following compiles which might suggest that if you want to just create a sequence or chain of these classes that you might be able to leverage them similarly to SingleCriteria.
I'm not saying you'd want to do this, but I did not know you could do this with Generics (declare the class multiple times with different generic types). So, if you wanted to be able to inline the use of a MultipleCriteria instance similarly to a SingleCriteria and be able to specify a dynamic number of parameters, there appears to be a "workable" solution here. (I haven't actually tried it).
public class Test<A> {}
public class Test<A, B> {}
public class Test<A, B, C> {}
object test = new Test<int>(); object test2 = new Test<int, string>(); object test3 = new Test<string, DateTime, string>();
It would be possible to create a whole set of Criteria classes with n generic parameters. SingleCriteria is where n=1, but you could do n=2, n=3, etc.
I chose not to do that, because I think you should create more self-documenting criteria classes if you have more than one value.
Remember, the results would be exposed in properties like Value1, Value2, Value3, etc. Very much not self-documenting. Really, at that point, why not just use a Dictionary?
That's certainly a valid point... you could just use object[] for singlecriteria anyways and just pass a new object[] { object1, object2, etc} which would be just as effective without creating any classes.
Nonetheless I didn't know you could do that with generic classes. I don't know of any instance where that would be useful but I didn't know you could do that.
Guys,
Thanks a lot for your replies.This has been very helpful.
I might create a criteria that handles a max of 5 params.
More than that and you have to create your own criteria classes.Not very self documenting,but that would be a trade off in some eyes.
Thanks
Copyright (c) Marimer LLC