Share Link
Copied to clipboard
Embed on Your Page
Copied to clipboard
We Stand with Ukraine
[Fork] [Fork] https://stackoverflow.com/questions/75912029/easiest-way-to-serialize-an-iparsablet-as-a-string-using-the-datacontract-mode by dbc_MinLength
Environment version: .NET 9.0.0 (9.0.0), Unix 6.8.0.1014

<?xml version="1.0" encoding="utf-16"?>
<MyType xmlns="https://stackoverflow.com/questions/75912029">{"Value1":"hello","Value2":"there"}</MyType>

Schema for MyType using root name "https://stackoverflow.com/questions/75912029:MyType"
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="https://stackoverflow.com/questions/75912029" targetNamespace="https://stackoverflow.com/questions/75912029" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="MyType" type="tns:MyType" />
  <xs:simpleType name="MyType">
    <xs:restriction base="xs:string" />
  </xs:simpleType>
</xs:schema>

MyType XML Validated successfully.

<?xml version="1.0" encoding="utf-16"?>
<Model xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/">
  <MyTypes xmlns:d2p1="https://stackoverflow.com/questions/75912029">
    <d2p1:MyType>{"Value1":"hello","Value2":"there"}</d2p1:MyType>
    <d2p1:MyType i:nil="true" />
    <d2p1:MyType>{"Value1":"foo","Value2":"bar"}</d2p1:MyType>
  </MyTypes>
</Model>
Cached Result
Last Run: 7:17:55 pm
Compile: 0.028s
Execute: 0.27s
Memory: 29.53Mb
CPU: 0.298s