// 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 { /// /// Base class for OpenTAP Serializer plugins. Implement this in a public class to extend the TapSerializer with additional functionality. /// [Display("Serializer")] public abstract class TapSerializerPlugin : ITapSerializerPlugin { /// Log source for serializer plugins. protected static TraceSource Log = OpenTap.Log.CreateSource("Serializer"); /// The object facilitating Serialization or Deserialization. protected TapSerializer Serializer { get; private set; } /// Creates a new TapSerializerPlugin. public TapSerializerPlugin() { this.Serializer = TapSerializer.GetCurrentSerializer(); } /// /// Priority of the serializer. Defines the order in which the serializers are used. Default is 0. /// public virtual double Order { get { return 0; } } /// /// Implement to deserialize an object. /// /// /// /// /// public abstract bool Deserialize(XElement node, ITypeData t, Action setter); /// /// Implement to serialize an object. /// /// /// /// /// public abstract bool Serialize(XElement node, object obj, ITypeData expectedType); } /// /// Helper class for writing warning messages about XML nodes. /// static class LogExtension { /// /// Prints the warning + Line information. /// /// /// /// /// 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)); } } }