コード例 #1
0
        public void CanUseTheDefaultNamespace()
        {
            var ser = new YAXSerializer(typeof(YAXLibMetadataOverriding));

            ser.YaxLibNamespacePrefix   = String.Empty;
            ser.YaxLibNamespaceUri      = "http://namespace.org/sample";
            ser.DimentionsAttributeName = "dm";
            ser.RealTypeAttributeName   = "type";

            var    sampleInstance = YAXLibMetadataOverriding.GetSampleInstance();
            string result         = ser.Serialize(sampleInstance);


            string expected =
                @"<YAXLibMetadataOverriding xmlns=""http://namespace.org/sample"">
  <IntArray dm=""2,3"">
    <Int32>1</Int32>
    <Int32>2</Int32>
    <Int32>3</Int32>
    <Int32>2</Int32>
    <Int32>3</Int32>
    <Int32>4</Int32>
  </IntArray>
  <Obj type=""System.String"">Hello, World!</Obj>
</YAXLibMetadataOverriding>";

            Assert.That(result, Is.EqualTo(expected));

            var desObj = (YAXLibMetadataOverriding)ser.Deserialize(expected);

            Assert.That(desObj.Obj.ToString(), Is.EqualTo(sampleInstance.Obj.ToString()));
            Assert.That(desObj.IntArray.Length, Is.EqualTo(sampleInstance.IntArray.Length));
        }
コード例 #2
0
        public void CanSuppressMetadata()
        {
            var ser = new YAXSerializer(typeof(YAXLibMetadataOverriding),
                YAXSerializationOptions.SuppressMetadataAttributes);

            var sampleInstance = YAXLibMetadataOverriding.GetSampleInstance();
            var result = ser.Serialize(sampleInstance);

            var expected =
                @"<YAXLibMetadataOverriding>
  <IntArray>
    <Int32>1</Int32>
    <Int32>2</Int32>
    <Int32>3</Int32>
    <Int32>2</Int32>
    <Int32>3</Int32>
    <Int32>4</Int32>
  </IntArray>
  <Obj>Hello, World!</Obj>
</YAXLibMetadataOverriding>";
            Assert.That(result, Is.EqualTo(expected));
        }