I'm having a very similar issue when attempting to use ISerializable to "lighten" some objects; we're wanting the IsDirty, IsValid, etc. to try and keep our validation intact. Cloning the object and not including these properties renders the validation useless. Maybe using ValidationRules.CheckRules() after deserializing is an acceptable solution, just wanted some input from the forum...
Any help would be greatly appreciated.
I'll start by saying that my info relates to pre-3.5 versions of CSLA, as I haven't had time to look at that. I would imagine that 3.5 works similarly, but that's just a guess.
It's a little tough to answer your questions, because I'm not sure why you're choosing this route. If you want to "lighten" your objects, why not simply apply a "NonSerialized" (and probably "NotUndoable" as well) attribute to those properties that you don't want to serialize? The OP doesn't say why he's implementing ISerializable, so I can't speak to that, but I'm wondering if this won't get you where you want to go.
In a more general sense, you're going to have issues if you try to apply any sort of custom serialization, for exactly the reasons you're running into. CSLA just wasn't built to handle ISerializable out of the box - that's why there is "NotUndoable" and "NonSerialized". Unless all the base properties are serialized, CSLA-based objects won't work properly. Calling "CheckRules" might help with IsDirty/IsValid, but it won't help with IsNew, IsDeleted, etc. And you need those for the DP_ code to work. Plus, you'll have issues with things like DeletedList as well, if you have collections you need to deal with.
You can certainly use reflection to get at what you need, and you could use the "Mark" routines in your deserialization code to help with the listed properties. But you would still need to include those base properties in your serialization code, along with all the other base CSLA data - if you implement ISerializable, you're pretty much on your own.
HTH
- Scott
Scott is right, you would be far better off using the NonSerialized attribute.
When you implement ISerializable, you hijack the normal serialization process, and it becomes your responsibility to serialize the fields of your object. Typically this means using reflection to get/set the values (which is what the serializer would have done for you automatically).
This can get very messy if you end up reflecting against any fields that contain other objects that implement ISerializable, because you need to participate in the serializer's "fix-up" processing stage. I don't know how you actually do that, I just know that's what's required - and it is rather arcane...
If you have fields you don't want serialized - that's what NonSerialized is for, and I strongly recommend you take that approach.
Copyright (c) Marimer LLC