SXmlSerializable shape for fixing Jon Skeet's problems in C# 9.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The IXmlSerializable interface assumes the mutability of the type the implements it. | |
Now we have readonly structs, that's not a valid assumption. Ideally, there'd be a static | |
method that returned a new instance of the type, but you can't have static methods on | |
interfaces, because reasons. | |
*/ | |
[Deprecated] | |
public interface IXmlSerializable | |
{ | |
void WriteXml(XmlWriter writer); | |
[Obsolete("This seemed like a good idea in 2002, but it causes problems here in 2022")] | |
void ReadXml(XmlReader reader); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
There's an open C# language discussion for something called Shapes, which are like interfaces | |
but much, much better, and they do allow static methods to be declared, which would allow the | |
following syntax: | |
*/ | |
public shape SXmlSerializable<T> | |
{ | |
void WriteXml(XmlWriter writer); | |
static T ReadXml(XmlReader reader); | |
} | |
// Learn more about Shapes at https://github.com/dotnet/csharplang/issues/164 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment