/// <summary> /// Adds a tag over the given span. /// </summary> /// <param name="span">The <see cref="ITrackingSpan"/> that tracks the tag across text versions.</param> /// <param name="tag">The tag to associate with the given span.</param> /// <returns>The <see cref="TrackingTagSpan<T>"/> that was added, which can be used to remove the tag later on.</returns> /// <remarks>This method is safe to use from any thread.</remarks> /// <exception cref="ArgumentNullException"><paramref name="span"/> or <paramref name="tag"/> is null.</exception> public TrackingTagSpan <T> CreateTagSpan(ITrackingSpan span, T tag) { if (span == null) { throw new ArgumentNullException("span"); } if (tag == null) { throw new ArgumentNullException("tag"); } var tagSpan = new TrackingTagSpan <T>(span, tag); StartBatch(); try { lock (mutex) { _trackingTagSpans.Add(tagSpan); UpdateBatchSpan(tagSpan.Span); } } finally { EndBatch(); } return(tagSpan); }
/// <summary> /// Removes a tag span that was created by calling <see cref="CreateTagSpan"/>. /// </summary> /// <param name="tagSpan">The <see cref="TrackingTagSpan<T>"/> returned from a previous call to <see cref="CreateTagSpan"/>.</param> /// <returns><c>true</c> if removed successfully, otherwise <c>false</c>.</returns> /// <remarks>This method is safe to use from any thread.</remarks> public bool RemoveTagSpan(TrackingTagSpan <T> tagSpan) { if (tagSpan == null) { throw new ArgumentNullException("tagSpan"); } bool removed = false; StartBatch(); try { lock (mutex) { // Find the tracking tag span to be removed removed = (_trackingTagSpans.Remove(tagSpan)); if (removed) { UpdateBatchSpan(tagSpan.Span); } } } finally { EndBatch(); } return(removed); }