From cf7b171d2af220080fe4514b055d8f131aa6300f Mon Sep 17 00:00:00 2001 From: Liudmila Molkova Date: Tue, 5 Mar 2024 16:12:27 -0800 Subject: [PATCH] core ci --- .../Azure.Core/src/Shared/EventSourceEvent.cs | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/sdk/core/Azure.Core/src/Shared/EventSourceEvent.cs b/sdk/core/Azure.Core/src/Shared/EventSourceEvent.cs index 5bb092bafe5c3..3defc9924ee02 100644 --- a/sdk/core/Azure.Core/src/Shared/EventSourceEvent.cs +++ b/sdk/core/Azure.Core/src/Shared/EventSourceEvent.cs @@ -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> + internal readonly struct EventSourceEvent : IReadOnlyList> { public EventWrittenEventArgs EventData { get; } @@ -16,11 +19,16 @@ public EventSourceEvent(EventWrittenEventArgs eventData) EventData = eventData; } - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { + if (EventData.PayloadNames == null || EventData.Payload == null) + { + yield break; + } + for (int i = 0; i < Count; i++) { - yield return new KeyValuePair(EventData.PayloadNames[i], EventData.Payload[i]); + yield return new KeyValuePair(EventData.PayloadNames[i], EventData.Payload[i]); } } @@ -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 this[int index] => new KeyValuePair(EventData.PayloadNames[index], EventData.Payload[index]); + public KeyValuePair 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(EventData.PayloadNames[index], EventData.Payload[index]); + } + } } }