// 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.Collections.Generic;
using System.Xml.Linq;
namespace OpenTap.Plugins
{
/// Serializer implementation for IDynamicStep.
/// It needs to act like an object serializer, which is why it inherits from it.
/// It implementes TapSerializerPlugin, so it can explicitly override serializer behavior.
internal class DynamicStepSerializer : ObjectSerializer
{
/// The order of this serializer.
public override double Order { get { return new TestStepSerializer().Order + 1; } }
///
/// Serializes a dynamic step.
///
///
///
///
///
public override bool Serialize(XElement elem, object obj, ITypeData expectedType)
{
if (obj is IDynamicStep == false) return false;
if (serializing.Contains(elem)) return false;
var step = (IDynamicStep)obj;
try
{
serializing.Add(elem);
return Serializer.Serialize(elem, obj, expectedType);
}
finally
{
serializing.Remove(elem);
elem.SetAttributeValue("type", step.GetStepFactoryType().FullName);
}
}
/// Deserialization implementation.
public override bool Deserialize(XElement elem, ITypeData t, Action