chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//            Copyright Keysight Technologies 2012-2019
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
using System;
using System.Xml.Linq;
 
namespace OpenTap
{
    /// <summary>
    /// Base class for OpenTAP Serializer plugins. Implement this in a public class to extend the TapSerializer with additional functionality.
    /// </summary>
    [Display("Serializer")]
    public abstract class TapSerializerPlugin : ITapSerializerPlugin
    {
        /// <summary> Log source for serializer plugins. </summary>
        protected static TraceSource Log = OpenTap.Log.CreateSource("Serializer");
        
        /// <summary> The object facilitating Serialization or Deserialization. </summary>
        protected TapSerializer Serializer { get; private set; }
        
        /// <summary> Creates a new TapSerializerPlugin. </summary>
        public TapSerializerPlugin()
        {
            this.Serializer = TapSerializer.GetCurrentSerializer();
        }
        /// <summary>
        /// Priority of the serializer. Defines the order in which the serializers are used. Default is 0.  
        /// </summary>
        public virtual double Order { get { return 0; } }
 
        /// <summary>
        /// Implement to deserialize an object.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="t"></param>
        /// <param name="setter"></param>
        /// <returns></returns>
        public abstract bool Deserialize(XElement node, ITypeData t, Action<object> setter);
 
        /// <summary>
        /// Implement to serialize an object.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="obj"></param>
        /// <param name="expectedType"></param>
        /// <returns></returns>
        public abstract bool Serialize(XElement node, object obj, ITypeData expectedType);
    }
 
    /// <summary>
    /// Helper class for writing warning messages about XML nodes.
    /// </summary>
    static class LogExtension
    {
        /// <summary>
        /// Prints the warning + Line information.
        /// </summary>
        /// <param name="log"></param>
        /// <param name="node"></param>
        /// <param name="message"></param>
        /// <param name="args"></param>
        public static void Warning(this TraceSource log, XElement node, string message, params object[] args)
        {
            var lineinfo = ((System.Xml.IXmlLineInfo)node);
            log.Warning("XML line {0} column {1}: {2}", lineinfo.LineNumber, lineinfo.LinePosition, string.Format(message, args));
        }
    }
 
}