Can I constrain a template parameter class to implement the interfaces that are supported by other?

You could eliminate ICondition entirely and just use Predicates and functional style. Here's a sample static way to make one: public static Predicate CountLessThan (int value) where T:ICount { return (T item) => item. Count anded = x => CountLessThan(5)(x) && CountLessThan(3)(x) You could also create extension methods like this to combine predicates: public static Predicate And(this Predicate first, Predicate second) { return (T item) => first(item) && second(item); } An alternative would be to have a base, abstract, generic Condition class from which your other conditions derive and then implement And, Or, ... in the base condition class allowing for a fluent interface like: new CountLessThan(5).

And(new CountLessThan(3)) Being generic in T would ensure that you could only combine conditions that have the same T.

You could eliminate ICondition entirely and just use Predicates and functional style. Here's a sample static way to make one:- public static Predicate CountLessThan (int value) where T:ICount { return (T item) => item. Count anded = x => CountLessThan(5)(x) && CountLessThan(3)(x); You could also create extension methods like this to combine predicates:- public static Predicate And(this Predicate first, Predicate second) { return (T item) => first(item) && second(item); } An alternative would be to have a base, abstract, generic Condition class from which your other conditions derive and then implement And, Or, ... in the base condition class allowing for a fluent interface like:- ... = new CountLessThan(5).

And(new CountLessThan(3)) Being generic in T would ensure that you could only combine conditions that have the same T.

But the problem is still there: CountLessThan requires T : ICount, but CurrentNormLessThan requires T : ICurrent, so these are different T's. Your code will look like this: Predicate And(this Predicate first, Predicate second) where T1 : ICount where T2 : ICurrent where Both : ICount, ICurrent; The And should accept only those classes, which implement the union of the interfaces, required by the 2 arguments. – K.

Georgiev Jun 6 '10 at 22:32 And works if you actually have a Both class that implements both interfaces, but what you want is a Predicate that can be used with a BothA or a BothB provided they implement the two interfaces mentioned in building the And predicate, right? Not one that's tied to just Both. I see ... – ghtechrider Jun 6 '10 at 22:52 Sorry, And wasn't meant to have the interface on it, all it needs is two Predicates of the same T to work.Fixed.

– ghtechrider Jun 6 '10 at 23:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions