Two sets of serialization attributes in one class

I ran into a class design problem.

I am using a data serializer.

So, in the assembly that is used in all my applications, I have something like this:

// Assembly DataContracts.dll: .NET 3.0, used by every subsystems
[DataContract]
public class User
{
    /// <summary>Nickname.</summary>
    [DataMember]
    public string displayName;
}

There are many more fields: I left only displayName, trying to compose my codelists.

However, one application is a server that requires the following serializer to apply to a single class, as follows:

// Assembly ServerDatabase.dll, .NET 4.0, used only by server.
[EseTable]
public class User
{
    /// <summary>Nickname.</summary>
    [EseText(bUnicode=true, maxChars=71)]
    public string displayName;
}

ServerDatabase.dll is associated with .NET 4. In addition, the [Ese *] attributes are defined in DLLs that can only be loaded by the server component due to reasons due to my control, so I cannot just have one class with both sets of attributes shared by each subsystem.

I am currently writing 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 I need to implement an upcasting copy constructor, to convert from User to UserRecord :-(
    public UserRecord(User that)
    {
        base.displayName=that.displayName;
    }
}

: . , ?

!

+3
1

, , , "" ( , ).

DTO "" . , , AutoMapper. - , , . , .

automapper , DTO DCS DCS , ..

[EseTable, DataContract]
public class User
{
    /// <summary>Nickname.</summary>
    [EseText(bUnicode=true, maxChars=71), DataMember]
    public string displayName;
}

, DCS . .. DCS . ( , DCS - ; p)

0

All Articles