Exemple #1
0
        public bool Deserialize(XElement node, ITypeData t, Action <object> setter)
        {
            if (t.IsA(typeof(Verdict)))
            {
                if (node.Value == legacyNotSetName)
                {
                    node.SetValue(nameof(Verdict.NotSet));
                    return(TapSerializer.GetCurrentSerializer().Serialize(node, setter, t));
                }
            }

            if (node.Name == TestStepName && t.DescendsTo(typeof(DialogStep)))
            {
                if (currentBox != null)
                {
                    return(false);
                }

                currentBox = new Box();
                var serializer = TapSerializer.GetCurrentSerializer();
                return(serializer.Deserialize(node, x =>
                {
                    currentBox.Step = (DialogStep)x;
                    setter(x);
                }, t));
            }
            else if (currentBox != null && node.Name == legacyDefaultAnswerPropertyName)
            {
                if (bool.TryParse(node.Value, out bool defaultAnswer))
                {
                    node.Remove();
                    var serializer = TapSerializer.GetCurrentSerializer();
                    var thisbox    = currentBox;
                    serializer.DeferLoad(() =>
                    {
                        if (thisbox.Step == null)
                        {
                            return;
                        }
                        if (defaultAnswer)
                        {
                            thisbox.Step.DefaultAnswer = thisbox.Step.PositiveAnswer;
                        }
                        else
                        {
                            thisbox.Step.DefaultAnswer = thisbox.Step.NegativeAnswer;
                        }
                    });
                    return(true);
                }
            }
            return(false);
        }
        public bool Deserialize(XElement node, ITypeData t, Action <object> setter)
        {
            // 1. 'Iterate and Replace' if the node is the test plan node, we want to find all test step sub-nodes and replace the types.
            if (t.DescendsTo(typeof(TestPlan)))
            {
                iterateAndReplaceTypesInXml(node, node);
            }
            else if (node.Attribute(postScaleAttr) is XAttribute attribute)
            {
                // 2. do post-scaling.
                // when the old step was detected the property was marked with this post-scale attribute to show that it should scale it after deserialization.
                // this is because the old step used milliseconds, but the new one uses seconds.

                attribute.Remove(); // remove the attribute to avoid hitting this again.

                // this new setter applies the post-scaling that was added to the attributes during 'iterate and replace'.
                Action <object> newSetter = x => setter(double.Parse(x.ToString()) * double.Parse(attribute.Value));

                // call the deserializer to actually deserialize the property, but direct it to use the new setter instead of the original.
                return(TapSerializer.GetCurrentSerializer().Deserialize(node, newSetter, t));
            }

            return(false);
        }