If you find yourself having to stack many KnownType attributes on a class that is sent over the wire for WCF communication, there is a slick alternative.
Instead of something like this:
You can specify a method to reflectively return all of the types for you:
And here is the GetDerivedTypes() extension method:
Now we no longer have to add new KnownType attibutes every time we have a new subtype. Nice, eh?
2 comments:
What if we have classes in different assemblies ???
Then we would change the GetDerivedTypes() method to do more than just look in the current assembly.
Post a Comment