private void CreateAnnotations(XmlReader reader, TrackingAnnotationCollection annotations) { if (null == reader) throw new ArgumentNullException("reader"); if (null == annotations) throw new ArgumentNullException("annotations"); if (0 != string.Compare(reader.Name, "Annotations", StringComparison.Ordinal)) throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationInvalidPosition + "Annotations."); if (reader.IsEmptyElement) return; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (0 == string.Compare(reader.Name, "Annotation", StringComparison.Ordinal)) { // // Preserve null and empty as distinct values // null == <Annotation /> empty string = <Annotation></Annotation> if (!reader.IsEmptyElement) annotations.Add(reader.ReadString()); else annotations.Add(null); } break; case XmlNodeType.EndElement: if (0 == string.Compare(reader.Name, "Annotations", StringComparison.Ordinal)) return; break; } } // // Only valid exit is on an EndElement that matches the element that is passed in. throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + "Annotations."); }
private void CreateAnnotations(XmlReader reader, TrackingAnnotationCollection annotations) { if (reader == null) { throw new ArgumentNullException("reader"); } if (annotations == null) { throw new ArgumentNullException("annotations"); } if (string.Compare(reader.Name, "Annotations", StringComparison.Ordinal) != 0) { throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationInvalidPosition + "Annotations."); } if (!reader.IsEmptyElement) { while (true) { if (!reader.Read()) { throw new TrackingProfileDeserializationException(ExecutionStringManager.TrackingDeserializationCloseElementNotFound + "Annotations."); } switch (reader.NodeType) { case XmlNodeType.Element: if (string.Compare(reader.Name, "Annotation", StringComparison.Ordinal) == 0) { if (!reader.IsEmptyElement) { annotations.Add(reader.ReadString()); } else { annotations.Add(null); } } break; case XmlNodeType.EndElement: if (string.Compare(reader.Name, "Annotations", StringComparison.Ordinal) == 0) { return; } break; } } } }