Exemplo n.º 1
0
        /// <summary>
        /// Writes a collection of instance annotations in ATOM format.
        /// </summary>
        /// <param name="instanceAnnotations">Instance annotation collection to write.</param>
        /// <param name="tracker">The tracker to track which instance annotations have been written.</param>
        internal void WriteInstanceAnnotations(IEnumerable <AtomInstanceAnnotation> instanceAnnotations, InstanceAnnotationWriteTracker tracker)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(instanceAnnotations != null, "instanceAnnotations should not be null if we called this");
            Debug.Assert(tracker != null, "tracker should not be null if we called this");

            HashSet <string> instanceAnnotationNames = new HashSet <string>(StringComparer.Ordinal);

            foreach (var annotation in instanceAnnotations)
            {
                if (!instanceAnnotationNames.Add(annotation.TermName))
                {
                    throw new ODataException(ODataErrorStrings.JsonLightInstanceAnnotationWriter_DuplicateAnnotationNameInCollection(annotation.TermName));
                }

                if (!tracker.IsAnnotationWritten(annotation.TermName))
                {
                    this.WriteInstanceAnnotation(annotation);
                    tracker.MarkAnnotationWritten(annotation.TermName);
                }
            }
        }