WCF: Attack Of The Generics
I am trying to learn WCF, and I am simply amazed at the amount of Something<T> that they have all over the place. Yes, strongly typing it a wonderful thing, but I think that they went too far with it. (And I am speaking as someone who used generics to give you compile time errors about misformed database queries!)
Let us take ChannelFactory<T> for instnace, I can't use it without specifying a type parameter. All fine and good, until I need to construct a proxy from its System.Type, in a late bound fashion. Then it starts to get ugly. This is particulary annoying since as far as I can reflect, I am seeing that the underlying ServiceChannelFactory does not use the generic model, so I could make it work with a System.Type object. The problem is that again, someone decided to slap internal on useful types.
This leads to... interesting code, shall we say, when it comes to dealing with ChannelFactory in a generic fashion (i.e, not against a specific service, but against several). This is me after about 30 minutes of starting to play with WCF. I just hate it when I run into brick walls so fast.
Comments
I ran into the same thing when I was looking into their Ent Lib Validation Application Block. You can't get a Validator<T> without specifying a type parameter. Those kinds of decisions seem juvenile.
You can actually dynamically create a generic type using reflection. See my blog entry here: http://programcsharp.com/blog/archive/2006/05/02/20524.aspx
The Type.MakeGenericType method is the key.
Yes, I know, see my next post about this subject,when I make use of this technique.
The problem is that this raises the complexity by a fair bit.
Oops. I didn't notice that -- was reading posts earliest to latest. Gotta love reflection ;-).
Comment preview