Mixing custom and basic serialization?

I have a class with more than 100 properties (this is a database mapping class), and one of the properties should be in the method. In other words, this data is not displayed through a property, but through methods:

"ABCType GetABC (), SetABC (value ABCType)"

All this is very different from C #. I shudder when I see this.

The class must be serializable so that it can be sent through web services, and the data obtained by Get / Set methods must also be serialized. (Due to the strange thing that I use the network is reflected in the method, it cannot process objects that contain properties of the same type as the containing object. The problem property preserves the initial state of the database object in If reverse is required. Ineffective implementation, yes, but I can't rebuild it.)

My question is this: since only this field 1 needs a special serialization code, I would like to use custom serialization only to call GetABC and SetABC, returning to the basic XML serialization for the rest of the class. This minimizes the chance of errors in my serialization code. Is there any way?

+1
c # xml serialization
source share
1 answer

The first thing I will try is to add a property for serialization, but hide it from the user interface:

[Browsable(false)] // hide in UI public SomeType ABC { get {return GetABC();} set {SetABC(value);} } 

Unfortunately, you cannot mix and match serialization; as soon as you implement IXmlSerializable , you own everything. If you used WCF, then DataContractSerialier supports non-public properties for serialization, so you can use:

 [DataMember] private SomeType ABC { get {return GetABC();} set {SetABC(value);} } 

but this does not apply to asmx web services via XmlSerializer .

Does the [Browsable] trick [Browsable] at all? Assuming the custom mesh uses a TypeDescriptor , another option might be to hide it using ICustomTypeDescriptor , but it's a lot of work to hide the property ...

+2
source share

All Articles