/// <summary> /// Read the start date from the stream and consume to the end of the payload. /// </summary> /// <param name="streamReader">The reader from which to read the start date.</param> /// <returns>The start date read from the payload.</returns> public static DateTimeOffset ReadStartDate(ref Utf8JsonStreamReader streamReader) { if (streamReader.TokenType != JsonTokenType.StartObject) { throw new JsonException("Expected to be at the start of the event payload."); } // Read the ID streamReader.Read(); if (streamReader.TokenType != JsonTokenType.PropertyName || !streamReader.Match(StartDatePropertyString)) { throw new JsonException($"Expected to find the {StartDatePropertyString}."); } streamReader.Read(); if (streamReader.TokenType != JsonTokenType.String) { throw new JsonException("Expected to find a string-encoded DateTimeOffset property."); } DateTimeOffset startDate = streamReader.GetDateTimeOffset(); // Read to the end of the object streamReader.Read(); if (streamReader.TokenType != JsonTokenType.EndObject) { throw new JsonException("Expected to be at the end of the event payload."); } return(startDate); }