Esempio n. 1
0
        public override bool RegisterReference(object referenced, XElement element, Recorder.Context recContext)
        {
            if (!refToElement.TryGetValue(referenced, out var xelement))
            {
                if (recContext.Referenceable)
                {
                    // Insert it into our refToElement mapping
                    refToElement[referenced] = element;
                    elementToRef[element]    = referenced;
                }
                else
                {
                    // Cannot be referenced, so we insert a fake null entry
                    refToElement[referenced] = null;

                    // Note: It is important not to add an elementToRef entry because this is later used to split long hierarchies
                    // and if you split a long hierarchy around a non-referencable barrier, everything breaks!
                }

                // We still need this to be generated, so we'll just let that happen now
                return(false);
            }

            if (xelement == null)
            {
                // This is an unreferencable object! We are in trouble.
                Dbg.Err("Attempt to create a new reference to an unreferenceable object. Will be left with default values.");
                return(true);
            }

            // We have a referencable target, but do *we* allow a reference?
            if (!recContext.Referenceable)
            {
                Dbg.Err("Attempt to create a new unreferenceable recording of a referenceable object. Will be left with default values.");
                return(true);
            }

            var refId = refToString.TryGetValue(referenced);

            if (refId == null)
            {
                // We already had a reference, but we don't have a string ID for it. We need one now though!
                refId = $"ref{referenceId++:D5}";
                refToString[referenced] = refId;
            }

            // Tag the XML element properly
            element.SetAttributeValue("ref", refId);

            // And we're done!
            return(true);
        }
Esempio n. 2
0
 public override bool RegisterReference(object referenced, XElement element, Recorder.Context recContext)
 {
     // We never register references in Compose mode.
     return(false);
 }
Esempio n. 3
0
 public abstract bool RegisterReference(object referenced, XElement element, Recorder.Context recContext);
Esempio n. 4
0
 public abstract WriterNode CreateMember(System.Reflection.FieldInfo field, Recorder.Context context);
Esempio n. 5
0
 // this needs to be more abstract
 public abstract WriterNode CreateChild(string label, Recorder.Context context);
Esempio n. 6
0
 public WriterNode(Recorder.Context context)
 {
     this.context = context;
 }