@@ -114,6 +114,13 @@ internal EventGridEvent(EventGridEventInternal eventGridEventInternal)
114114 /// <returns> Whether or not the event is a system event.</returns>
115115 public bool TryGetSystemEventData ( out object eventData )
116116 {
117+ // the property can be set to null after the creation of the event.
118+ if ( Data == null )
119+ {
120+ eventData = null ;
121+ return false ;
122+ }
123+
117124 try
118125 {
119126 JsonDocument requestDocument = JsonDocument . Parse ( Data . ToMemory ( ) ) ;
@@ -155,7 +162,7 @@ public static EventGridEvent[] ParseMany(BinaryData json)
155162 egEvents [ i ++ ] = new EventGridEvent ( EventGridEventInternal . DeserializeEventGridEventInternal ( property ) ) ;
156163 }
157164 }
158- return egEvents ?? Array . Empty < EventGridEvent > ( ) ;
165+ return egEvents ?? [ ] ;
159166 }
160167
161168 /// <summary>
@@ -171,19 +178,15 @@ public static EventGridEvent Parse(BinaryData json)
171178 {
172179 Argument . AssertNotNull ( json , nameof ( json ) ) ;
173180 EventGridEvent [ ] events = ParseMany ( json ) ;
174- if ( events . Length == 0 )
175- {
176- return null ;
177- }
178- if ( events . Length > 1 )
181+ return events . Length switch
179182 {
180- throw new ArgumentException (
183+ 0 => null ,
184+ > 1 => throw new ArgumentException (
181185 "The BinaryData instance contains JSON from multiple event grid events. This method " +
182- "should only be used with BinaryData containing a single event grid event. " +
183- Environment . NewLine +
184- $ "To parse multiple events, use the { nameof ( ParseMany ) } overload.") ;
185- }
186- return events [ 0 ] ;
186+ "should only be used with BinaryData containing a single event grid event. " + Environment . NewLine +
187+ $ "To parse multiple events, use the { nameof ( ParseMany ) } overload.") ,
188+ _ => events [ 0 ]
189+ } ;
187190 }
188191 }
189192}
0 commit comments