Ok, maybe this title is a little bit too catchy. However, I simply love the expressiveness of this little piece of code I wrote today.
1: public bool RegisterAll( Assembly assembly, Func<object, bool> isValidMessage )
3: if( assembly == null )
5: throw new ArgumentNullException( "assembly" );
7: if( isValidMessage == null )
9: throw new ArgumentNullException( "isValidMessage" );
11: var messages = from t in assembly.GetTypes()
12: where t.HasAttribute<MessageAttribute>() &&
13: isValidMessage( t )
14: select t;
15: return messages.All( Register );
would be even nicer and shorter if you used
I was a little anoyed by the
predicate argument test.
I don’t see why that is there. It is not passed in as an argument, so I can’t really grasp why it triggers a ArgumentException. So it not nice to look @ in insolation.
That’s what happens when you do last time changes without refactoring tools at your hand 😉
It was supposed to be isValidMessage, but I forgot to change it there.
Thanks for noticing.