Exemple #1
0
        /// <summary>Adds an external reference to the output XML, and records the filename to be serialized later.</summary>
        /// <param name="value">The external reference to add.</param>
        public void WriteExternalReference <T>(ExternalReference <T> value)
        {
            if (value == null || value.Filename == null)
            {
                return;
            }
            string relativePath = PathUtils.GetRelativePath(this.baseUri, value.Filename);
            string text         = null;

            foreach (IntermediateWriter.ExternalReference current in this.externalReferences)
            {
                if (current.TargetType == typeof(T) && current.Filename == relativePath)
                {
                    text = current.ID;
                    break;
                }
            }
            if (text == null)
            {
                text = "#External" + (this.externalReferences.Count + 1).ToString(CultureInfo.InvariantCulture);
                IntermediateWriter.ExternalReference item;
                item.TargetType = typeof(T);
                item.Filename   = relativePath;
                item.ID         = text;
                this.externalReferences.Add(item);
            }
            this.Xml.WriteElementString("Reference", text);
        }
Exemple #2
0
        /// <summary>Reads an external reference ID and records it for subsequent operations.</summary>
        /// <param name="existingInstance">The object receiving the data, or null if a new instance of the object should be created.</param>
        public void ReadExternalReference <T>(ExternalReference <T> existingInstance)
        {
            if (existingInstance == null)
            {
                throw new ArgumentNullException("existingInstance");
            }
            if (!this.MoveToElement("Reference"))
            {
                return;
            }
            string text = this.Xml.ReadElementContentAsString();

            if (!string.IsNullOrEmpty(text))
            {
                IntermediateReader.ExternalReferenceFixup item;
                item.ID         = text;
                item.TargetType = typeof(T);
                item.Fixup      = delegate(string filename)
                {
                    existingInstance.Filename = filename;
                };
                this.externalReferenceFixups.Add(item);
            }
        }