ActivityEvent
Represents an event containing a name and a timestamp, as well as an optional list of tags.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Diagnostics
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public readonly struct ActivityEvent
{
private static readonly IEnumerable<KeyValuePair<string, object>> s_emptyTags = Array.Empty<KeyValuePair<string, object>>();
private readonly Activity.TagsLinkedList ;
public string Name { get; }
public DateTimeOffset Timestamp { get; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
2
})]
public IEnumerable<KeyValuePair<string, object>> Tags {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
2
})]
get {
IEnumerable<KeyValuePair<string, object>> tags = _tags;
return tags ?? s_emptyTags;
}
}
public ActivityEvent(string name)
{
this = new ActivityEvent(name, DateTimeOffset.UtcNow, null);
}
public ActivityEvent(string name, DateTimeOffset timestamp = default(DateTimeOffset), [System.Runtime.CompilerServices.Nullable(2)] ActivityTagsCollection tags = null)
{
this = new ActivityEvent(name, timestamp, tags, tags?.Count ?? 0);
}
internal ActivityEvent(string name, DateTimeOffset timestamp, ref TagList tags)
{
this = new ActivityEvent(name, timestamp, tags, tags.Count);
}
private ActivityEvent(string name, DateTimeOffset timestamp, IEnumerable<KeyValuePair<string, object>> tags, int tagsCount)
{
Name = (name ?? string.Empty);
Timestamp = ((timestamp != default(DateTimeOffset)) ? timestamp : DateTimeOffset.UtcNow);
_tags = ((tagsCount > 0) ? new Activity.TagsLinkedList(tags) : null);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
0,
1,
2
})]
public Activity.Enumerator<KeyValuePair<string, object>> EnumerateTagObjects()
{
return new Activity.Enumerator<KeyValuePair<string, object>>(_tags?.First);
}
}
}