using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace OpenTap.Plugins
{
///
/// Serializes input/output relations. It does so by adding a collection of inputs to the step XML while serializing.
/// This is done because some of the properties might be read-only or XML ignore and in these cases we might still want
/// to serialize the relation ship between them, even though the values are not themselves serialized.
///
class InputOutputRelationSerializer : TapSerializerPlugin
{
class InputOutputMember
{
[XmlAttribute("id")]
public Guid Id { get; set; }
[XmlAttribute("member")]
public string Member { get; set; }
[XmlAttribute("target-member")]
public string TargetMember { get; set; }
public void Bind(ITestStepParent step, Func getStep)
{
ITestStepParent source;
if (Id == Guid.Empty)
{
source = step.GetParent();
}
else
{
source = getStep(Id);
}
if (source == null) return;
var sourceType = TypeData.GetTypeData(source);
var targetType = TypeData.GetTypeData(step);
var sourceMember = sourceType.GetMember(Member);
var targetMember = targetType.GetMember(TargetMember);
if(sourceMember != null && targetMember != null)
InputOutputRelation.Assign(step, targetMember, source, sourceMember);
}
}
static readonly XName stepInputsName = "TestStep.Inputs";
readonly HashSet activeElements = new HashSet();
readonly Dictionary> unusedInputs = new Dictionary>();
/// Deserialize input/output relations
public override bool Deserialize(XElement node, ITypeData t, Action