Skip to content

Commit

Permalink
core ci
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Mar 6, 2024
1 parent 9fc5143 commit cf7b171
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions sdk/core/Azure.Core/src/Shared/EventSourceEvent.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Tracing;

#nullable enable

namespace Azure.Core.Shared
{
internal readonly struct EventSourceEvent: IReadOnlyList<KeyValuePair<string, object>>
internal readonly struct EventSourceEvent : IReadOnlyList<KeyValuePair<string, object?>>
{
public EventWrittenEventArgs EventData { get; }

Expand All @@ -16,11 +19,16 @@ public EventSourceEvent(EventWrittenEventArgs eventData)
EventData = eventData;
}

public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
{
if (EventData.PayloadNames == null || EventData.Payload == null)
{
yield break;
}

for (int i = 0; i < Count; i++)
{
yield return new KeyValuePair<string, object>(EventData.PayloadNames[i], EventData.Payload[i]);
yield return new KeyValuePair<string, object?>(EventData.PayloadNames[i], EventData.Payload[i]);
}
}

Expand All @@ -29,13 +37,24 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}

public int Count => EventData.PayloadNames.Count;
public int Count => EventData.PayloadNames?.Count ?? 0;

public string Format()
{
return EventSourceEventFormatting.Format(EventData);
}

public KeyValuePair<string, object> this[int index] => new KeyValuePair<string, object>(EventData.PayloadNames[index], EventData.Payload[index]);
public KeyValuePair<string, object?> this[int index]
{
get
{
if (EventData.PayloadNames == null || EventData.Payload == null || index >= EventData.PayloadNames.Count)
{
throw new IndexOutOfRangeException("Index was out of range.");
}

return new KeyValuePair<string, object?>(EventData.PayloadNames[index], EventData.Payload[index]);
}
}
}
}

0 comments on commit cf7b171

Please sign in to comment.