c# - Two sets of serialization attributes on same class -


I am facing a class design problem.

I am using the Data Contract Serializer.

So, in the assembly shared in all my applications, I have something like this:

  // Assembly DataContracts.dll: .NET 3.0, each sub-systems Used by [DataContract] Public Class User {/// & lt; Summary & gt; Surname & Lt; / Summary & gt; [Datamember] public string displayName; }   

There are several more fields: I have just tried to compile DisplayName to compose your code lists.

However, an application is a server, which requires the implementation of another category in the following category:

  // assembly ServerDatabase.dll, .NET 4.0, Is used by the server only [assayable] public class user {/// & lt; Summary & gt; Surname & Lt; / Summary & gt; [EseText (bUnicode = true, maxChars = 71)] public string displayName; }   

ServerDatabase.dll is connected to .NET 4.. Apart from this, [AS *] attributes are defined in a DLL which can be loaded by the server component for security reasons only because of my control, so I have a combination with both the sets of properties shared by every subsystem There is no square.

Currently, I have written something like this:

  // DataContracts.dll [DataContract] Public class user {[DataMember} public string displayName; } // ServerDatabase.dll [EseTable] Public class UserRecord: User {[EseText (bUnicode = true, maxChars = 71)) New public string displayName {get {return base.displayName; } Set {base.displayName = value; }} // Note: In order to convert the user to UserRecord, I need to implement an upstream copy constructor :-( Public User Record (user key) {base.displayName = that.displayName;}}  < / Pre> 

I really do not like my solution: looks like a hack, and error prone. Any better solution, improvement or improvement?

Thanks in advance!

I do not think that The solution will work well because "other" serializer (if you can not see what I mean).

Personally, I will create a DTO layer for the "abnormal" level, and Map them among them. So, as an example in the question, maybe using an automaker. The alternative is whether the other serialized metadata supports support from sources other than attributes. Do not do anything.

If automaker causes a problem, then you can annotate your DTO with the same DCS properties, to translate the DCS model, i.e.

 < Code> [EseTable, DataContract] public class user {/// & lt; Summary & gt; Prevalent & Lt; / Summary & gt; [EseText (bUnicode = true, maxChars = 71), datamember] public string displayName; }   

Until the name matches, the DCS should be happy with this matter. I.e. to use the DCS to sort by a model and to deerize it as Other model. I use similar moves in some places (though I use my own serializer for it, not DCS-fast; P)

Comments