views:

445

answers:

1

I'm putting several legacy web services and the current web service into the same back end.

But I have to keep the old web services compatible with there old interface.

So my question:

Is there a way I can set several attributes on, for example, a property?

Like this:

[XmlElement("AvailableFrom",... what I need...)]
[XmlElement("Available",... what I need...)]
public DateTime AvailableFrom{get; set;}

One solution would be creating extra properties, but I really don't like the code bloat.

    private DateTime _availableFrom;

    [XmlElement("AvailableFrom")] 
    public DateTime AvailableFrom
    {
        get
        {
            return _availableFrom;
        }
        set
        {
            _availableFrom = value;
        }
    }

    [XmlElement("Available")] 
    public DateTime Available
    {
        get
        {
            return _availableFrom;   
        }
        set
        {
            _availableFrom = value;
        }
    }
+1  A: 

I think there is no simple way for you.

Serialization will fail because there could be two different values for one property. Which one is than the right one?

Perhaps some of my ideas can help you...

1) Create an XSLT to transform the current xml into the old format and back. In XSLT you are able to handle different values the best way.

or

2) Do not use SerialisationAttributes. Write your own method for it and handle the different values there.

or

3) Use your class as base and create two child classes. Fill the two child classes with overrides and the attributes for serialization.

michl86