C # Object serialization procedures with custom types

I created some custom types, for example:

public class Temperature
{
    protected double _celcius;

    public Temperature(){}

    public Temperature(double celcius)
    {
        _celcius = celcius;
    }

    public double Celcius
    {
        //sets & returns temperature in Celcius
    }

    public double Fahrenheit
    {
        //sets & returns temperature in Fahrenheit
    }
}

and similar for Massetc.

I also have a custom object, for example Planet, that uses these custom types as properties.

[Serializable]
public class Planet
{
    public int PositionFromSun;
    public Mass Mass;
    public Temperature Temperature;
}

What is the best practice for serialization Planetin this case, given that Massu Temperaturemight change a bit in the future (like adding Kelvinin Temperature)? Should I have Massand Temperatureinherit from the user interface something like IQuantity.

+3
source share
2 answers

See @Adriano comment . This is what I need.

, , . SO: XmlSerializer BinaryFormatter

+1

. (, xml), / .

, protobuf.Net - , .

0

All Articles