• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JaCraig / SerialBox / 11905976443

19 Nov 2024 03:59AM UTC coverage: 69.118%. First build
11905976443

push

github

JaCraig
feat: Updating to .Net 8/9 and workflow updates

- Migrating to .Net 8/9 due to issues with new MS packages.
- Updating workflows.
- Updated code to take advantage of .Net 8+ constructs.

BREAKING CHANGE: Removing .Net 6/7 support as .Net 9 dependencies say they work with it in the package but then throw warnings. I don't know why this approach was taken but it breaks a bunch of automation.

47 of 88 branches covered (53.41%)

Branch coverage included in aggregate %.

94 of 115 new or added lines in 8 files covered. (81.74%)

94 of 116 relevant lines covered (81.03%)

5.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/SerialBox/Default/XMLSerializer.cs
1
/*
2
Copyright 2016 James Craig
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
using SerialBox.BaseClasses;
18
using System;
19
using System.IO;
20
using System.Text;
21
using System.Xml.Serialization;
22

23
namespace SerialBox.Default
24
{
25
    /// <summary>
26
    /// XML serializer
27
    /// </summary>
28
    public class XMLSerializer : SerializerBase<string>
29
    {
30
        /// <summary>
31
        /// Initializes a new instance of the <see cref="XMLSerializer"/> class.
32
        /// </summary>
33
        public XMLSerializer()
7✔
34
        {
35
        }
7✔
36

37
        /// <summary>
38
        /// Content type (MIME type)
39
        /// </summary>
40
        public override string ContentType => "text/xml";
10✔
41

42
        /// <summary>
43
        /// File type
44
        /// </summary>
NEW
45
        public override string FileType => ".xml";
×
46

47
        /// <summary>
48
        /// Name
49
        /// </summary>
NEW
50
        public override string Name => "XML";
×
51

52
        /// <summary>
53
        /// Deserializes the data
54
        /// </summary>
55
        /// <param name="objectType">Object type</param>
56
        /// <param name="data">Data to deserialize</param>
57
        /// <returns>The deserialized data</returns>
58
        public override object? Deserialize(Type objectType, string data)
59
        {
60
            if (string.IsNullOrEmpty(data) || objectType == null)
3!
NEW
61
                return null;
×
62
            using var Stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
3✔
63
            var Serializer = new XmlSerializer(objectType);
3✔
64
            return Serializer.Deserialize(Stream);
3✔
65
        }
3✔
66

67
        /// <summary>
68
        /// Serializes the object
69
        /// </summary>
70
        /// <param name="objectType">Object type</param>
71
        /// <param name="data">Data to serialize</param>
72
        /// <returns>The serialized data</returns>
73
        public override string? Serialize(Type objectType, object data)
74
        {
75
            if (data == null || objectType == null)
3!
NEW
76
                return null;
×
77
            using var Stream = new MemoryStream();
3✔
78
            var Serializer = new XmlSerializer(objectType);
3✔
79
            Serializer.Serialize(Stream, data);
3✔
80
            Stream.Flush();
3✔
81
            var ResultingArray = Stream.ToArray();
3✔
82
            return new UTF8Encoding(false).GetString(ResultingArray, 0, ResultingArray.Length);
3✔
83
        }
3✔
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc