Seriosly, why? Why should we always implicitly write [Serializable]
? It makes me to write ugly code like this:
[Serializable]
public class SerializableFont
{
public string Name { get; set; }
public int Size { get; set; }
public SerializableFont() { }
public SerializableFont(string name, int size)
{
Name = name;
Size = size;
}
public static implicit operator Font(SerializableFont font)
{
return new Font(font.Name, font.Size);
}
}
or this
[Serializable]
public class SerializableColor
{
public string ColorHtml { get; set; }
public SerializableColor() { }
public static implicit operator Color(SerializableColor color)
{
return ColorTranslator.FromHtml(color.ColorHtml);
}
public static implicit operator SerializableColor(Color color)
{
return new SerializableColor { ColorHtml = ColorTranslator.ToHtml(color) };
}
}
or even when I want to run some code with closure in domain:
var domain = AppDomain.CreateDomain("DomainName");
string message = "Hello world!";
domain.DoCallBack(() => Console.WriteLine(message));
I get an exception
Unhandled Exception: System.Runtime.Serialization.SerializationException: Type 'MainProject.Program+<>c__DisplayClass1' in assembly 'LoadUnloadTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
All this issues could be easily avoided if all these types was [Serializable]
by default.