Bob said:
I see. I wonder why they can't specify constructors in interfaces...
Well, under normal circumstances, they don't make a lot of sense. You
can't instantiate an interface, so what good is a constructor? So this is
sort of the exception that proves the rule; it's the kind of thing that only
the Framework itself would use.
You wouldn't happen to know if there is a way to directly set
each member's value (from the type's GetMembers) when
desierializing? I'm guessing probably not, which is too bad because
that would make this workaround as complete as using built in
serialization/deserialization. The best generalization I could manage
is below, which should suffice for my needs.
I don't think there's any automatic way to do this; your way looks
pretty good to me, except for one thing: when serializing, I ignore
properties and only record fields -- after all, in almost all cases
properties are just wrappers for fields to begin with. Using Reflection
(and liberal use of the NonSerialized attribute where appropriate), I bet
you could automate serialization for simple classes fairly easily without
even touching property values. The problem for me comes from delegates --
those can be serialized, but you have to know the context first (normal
events, for instance, normally shouldn't be serialized).
Jeremy