22// Licensed under the MIT License.
33
44using System ;
5+ using System . Collections ;
56using System . Collections . Generic ;
67using System . Globalization ;
78using System . Text . Json ;
@@ -13,7 +14,7 @@ namespace Azure.Monitor.Query.Models
1314 /// Represents a row in the table of results returned from the logs query.
1415 /// </summary>
1516 [ CodeGenModel ( "LogsQueryResultRow" ) ]
16- public class LogsTableRow
17+ public class LogsTableRow : IReadOnlyList < object >
1718 {
1819 private readonly Dictionary < string , int > _columnMap ;
1920 private readonly IReadOnlyList < LogsTableColumn > _columns ;
@@ -35,113 +36,106 @@ internal LogsTableRow(Dictionary<string, int> columnMap, IReadOnlyList<LogsTable
3536 /// Gets the value of the column at the specified index as <see cref="int"/>.
3637 /// </summary>
3738 /// <param name="index">The column index.</param>
38- /// <returns>The <see cref="int "/> value of the column.</returns>
39- public int GetInt32 ( int index ) => _row [ index ] . GetInt32 ( ) ;
39+ /// <returns>The <see cref="Nullable{Int32} "/> value of the column.</returns>
40+ public int ? GetInt32 ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetInt32 ( ) ;
4041
4142 /// <summary>
4243 /// Gets the value of the column at the specified index as <see cref="long"/>.
4344 /// </summary>
4445 /// <param name="index">The column index.</param>
45- /// <returns>The <see cref="long "/> value of the column.</returns>
46- public long GetInt64 ( int index ) => _row [ index ] . GetInt64 ( ) ;
46+ /// <returns>The <see cref="Nullable{Int64} "/> value of the column.</returns>
47+ public long ? GetInt64 ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetInt64 ( ) ;
4748
4849 /// <summary>
4950 /// Gets the value of the column at the specified index as <see cref="bool"/>.
5051 /// </summary>
5152 /// <param name="index">The column index.</param>
52- /// <returns>The <see cref="bool "/> value of the column.</returns>
53- public bool GetBoolean ( int index ) => _row [ index ] . GetBoolean ( ) ;
53+ /// <returns>The <see cref="Nullable{Boolean} "/> value of the column.</returns>
54+ public bool ? GetBoolean ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetBoolean ( ) ;
5455
5556 /// <summary>
5657 /// Gets the value of the column at the specified index as <see cref="decimal"/>.
5758 /// </summary>
5859 /// <param name="index">The column index.</param>
59- /// <returns>The <see cref="decimal "/> value of the column.</returns>
60- public decimal GetDecimal ( int index ) => decimal . Parse ( _row [ index ] . GetString ( ) , CultureInfo . InvariantCulture ) ;
60+ /// <returns>The <see cref="Nullable{Decimal} "/> value of the column.</returns>
61+ public decimal ? GetDecimal ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : decimal . Parse ( _row [ index ] . GetString ( ) , CultureInfo . InvariantCulture ) ;
6162
6263 /// <summary>
6364 /// Gets the value of the column at the specified index as <see cref="double"/>.
6465 /// </summary>
6566 /// <param name="index">The column index.</param>
66- /// <returns>The <see cref="double "/> value of the column.</returns>
67- public double GetDouble ( int index ) => _row [ index ] . GetDouble ( ) ;
67+ /// <returns>The <see cref="Nullable{Double} "/> value of the column.</returns>
68+ public double ? GetDouble ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetDouble ( ) ;
6869
6970 /// <summary>
7071 /// Gets the value of the column at the specified index as <see cref="string"/>.
7172 /// </summary>
7273 /// <param name="index">The column index.</param>
7374 /// <returns>The <see cref="string"/> value of the column.</returns>
74- public string GetString ( int index ) => _row [ index ] . GetString ( ) ;
75+ public string GetString ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetString ( ) ;
7576
7677 /// <summary>
7778 /// Gets the value of the column at the specified index as <see cref="DateTimeOffset"/>.
7879 /// </summary>
7980 /// <param name="index">The column index.</param>
80- /// <returns>The <see cref="DateTimeOffset"/> value of the column.</returns>
81- public DateTimeOffset GetDateTimeOffset ( int index ) => _row [ index ] . GetDateTimeOffset ( ) ;
81+ /// <returns>The <see cref="Nullable{ DateTimeOffset} "/> value of the column.</returns>
82+ public DateTimeOffset ? GetDateTimeOffset ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetDateTimeOffset ( ) ;
8283
8384 /// <summary>
8485 /// Gets the value of the column at the specified index as <see cref="TimeSpan"/>.
8586 /// </summary>
8687 /// <param name="index">The column index.</param>
87- /// <returns>The <see cref="TimeSpan"/> value of the column.</returns>
88- public TimeSpan GetTimeSpan ( int index ) => _row [ index ] . GetTimeSpan ( "c" ) ;
88+ /// <returns>The <see cref="Nullable{ TimeSpan} "/> value of the column.</returns>
89+ public TimeSpan ? GetTimeSpan ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetTimeSpan ( "c" ) ;
8990
9091 /// <summary>
9192 /// Gets the value of the column at the specified index as <see cref="Guid"/>.
9293 /// </summary>
9394 /// <param name="index">The column index.</param>
94- /// <returns>The <see cref="Guid"/> value of the column.</returns>
95- public Guid GetGuid ( int index ) => _row [ index ] . GetGuid ( ) ;
95+ /// <returns>The <see cref="Nullable{ Guid} "/> value of the column.</returns>
96+ public Guid ? GetGuid ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : _row [ index ] . GetGuid ( ) ;
9697
9798 /// <summary>
9899 /// Gets the value of the column at the specified index as <see cref="BinaryData"/>.
99100 /// </summary>
100101 /// <param name="index">The column index.</param>
101102 /// <returns>The <see cref="BinaryData"/> value of the column.</returns>
102- public BinaryData GetDynamic ( int index ) => new BinaryData ( _row [ index ] . GetString ( ) ) ;
103-
104- /// <summary>
105- /// Returns <c>true</c> if the value of the column at the specified index is <c>null</c>, otherwise <c>false</c>.
106- /// </summary>
107- /// <param name="index">The column index.</param>
108- /// <returns><c>true</c> if the value is <c>null</c>, otherwise <c>false</c>.</returns>
109- public bool IsNull ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ;
103+ public BinaryData GetDynamic ( int index ) => _row [ index ] . ValueKind == JsonValueKind . Null ? null : new BinaryData ( _row [ index ] . GetString ( ) ) ;
110104
111105 /// <summary>
112106 /// Gets the value of the column with the specified name as <see cref="int"/>.
113107 /// </summary>
114108 /// <param name="name">The column name.</param>
115- /// <returns>The <see cref="int "/> value of the column.</returns>
116- public int GetInt32 ( string name ) => GetInt32 ( _columnMap [ name ] ) ;
109+ /// <returns>The <see cref="Nullable{Int32} "/> value of the column.</returns>
110+ public int ? GetInt32 ( string name ) => GetInt32 ( _columnMap [ name ] ) ;
117111
118112 /// <summary>
119113 /// Gets the value of the column with the specified name as <see cref="long"/>.
120114 /// </summary>
121115 /// <param name="name">The column name.</param>
122- /// <returns>The <see cref="long "/> value of the column.</returns>
123- public long GetInt64 ( string name ) => GetInt64 ( _columnMap [ name ] ) ;
116+ /// <returns>The <see cref="Nullable{Int64} "/> value of the column.</returns>
117+ public long ? GetInt64 ( string name ) => GetInt64 ( _columnMap [ name ] ) ;
124118
125119 /// <summary>
126120 /// Gets the value of the column with the specified name as <see cref="bool"/>.
127121 /// </summary>
128122 /// <param name="name">The column name.</param>
129- /// <returns>The <see cref="bool "/> value of the column.</returns>
130- public bool GetBoolean ( string name ) => GetBoolean ( _columnMap [ name ] ) ;
123+ /// <returns>The <see cref="Nullable{Boolean} "/> value of the column.</returns>
124+ public bool ? GetBoolean ( string name ) => GetBoolean ( _columnMap [ name ] ) ;
131125
132126 /// <summary>
133127 /// Gets the value of the column with the specified name as <see cref="decimal"/>.
134128 /// </summary>
135129 /// <param name="name">The column name.</param>
136- /// <returns>The <see cref="decimal "/> value of the column.</returns>
137- public decimal GetDecimal ( string name ) => GetDecimal ( _columnMap [ name ] ) ;
130+ /// <returns>The <see cref="Nullable{Decimal} "/> value of the column.</returns>
131+ public decimal ? GetDecimal ( string name ) => GetDecimal ( _columnMap [ name ] ) ;
138132
139133 /// <summary>
140134 /// Gets the value of the column with the specified name as <see cref="double"/>.
141135 /// </summary>
142136 /// <param name="name">The column name.</param>
143- /// <returns>The <see cref="double "/> value of the column.</returns>
144- public double GetDouble ( string name ) => GetDouble ( _columnMap [ name ] ) ;
137+ /// <returns>The <see cref="Nullable{Double} "/> value of the column.</returns>
138+ public double ? GetDouble ( string name ) => GetDouble ( _columnMap [ name ] ) ;
145139
146140 /// <summary>
147141 /// Gets the value of the column with the specified name as <see cref="string"/>.
@@ -154,22 +148,22 @@ internal LogsTableRow(Dictionary<string, int> columnMap, IReadOnlyList<LogsTable
154148 /// Gets the value of the column with the specified name as <see cref="DateTimeOffset"/>.
155149 /// </summary>
156150 /// <param name="name">The column name.</param>
157- /// <returns>The <see cref="DateTimeOffset"/> value of the column.</returns>
158- public DateTimeOffset GetDateTimeOffset ( string name ) => GetDateTimeOffset ( _columnMap [ name ] ) ;
151+ /// <returns>The <see cref="Nullable{ DateTimeOffset} "/> value of the column.</returns>
152+ public DateTimeOffset ? GetDateTimeOffset ( string name ) => GetDateTimeOffset ( _columnMap [ name ] ) ;
159153
160154 /// <summary>
161155 /// Gets the value of the column with the specified name as <see cref="TimeSpan"/>.
162156 /// </summary>
163157 /// <param name="name">The column name.</param>
164- /// <returns>The <see cref="TimeSpan"/> value of the column.</returns>
165- public TimeSpan GetTimeSpan ( string name ) => GetTimeSpan ( _columnMap [ name ] ) ;
158+ /// <returns>The <see cref="Nullable{ TimeSpan} "/> value of the column.</returns>
159+ public TimeSpan ? GetTimeSpan ( string name ) => GetTimeSpan ( _columnMap [ name ] ) ;
166160
167161 /// <summary>
168162 /// Gets the value of the column with the specified name as <see cref="Guid"/>.
169163 /// </summary>
170164 /// <param name="name">The column name.</param>
171- /// <returns>The <see cref="Guid"/> value of the column.</returns>
172- public Guid GetGuid ( string name ) => GetGuid ( _columnMap [ name ] ) ;
165+ /// <returns>The <see cref="Nullable{ Guid} "/> value of the column.</returns>
166+ public Guid ? GetGuid ( string name ) => GetGuid ( _columnMap [ name ] ) ;
173167
174168 /// <summary>
175169 /// Gets the value of the column with the specified name as <see cref="Guid"/>.
@@ -178,25 +172,13 @@ internal LogsTableRow(Dictionary<string, int> columnMap, IReadOnlyList<LogsTable
178172 /// <returns>The <see cref="BinaryData"/> value of the column.</returns>
179173 public BinaryData GetDynamic ( string name ) => GetDynamic ( _columnMap [ name ] ) ;
180174
181- /// <summary>
182- /// Returns true if the value of the column with the specified name is null, otherwise false.
183- /// </summary>
184- /// <param name="name">The column name.</param>
185- /// <returns><c>true</c> if the value is <c>null</c>, otherwise <c>false</c>.</returns>
186- public bool IsNull ( string name ) => IsNull ( _columnMap [ name ] ) ;
187-
188175 /// <summary>
189176 /// Gets the value of the column at the specified index as <see cref="object"/>.
190177 /// </summary>
191178 /// <param name="index">The column index.</param>
192179 /// <returns>The <see cref="object"/> value of the column.</returns>
193180 internal object GetObject ( int index )
194181 {
195- if ( IsNull ( index ) )
196- {
197- return null ;
198- }
199-
200182 var element = _row [ index ] ;
201183 switch ( _columns [ index ] . Type . ToString ( ) )
202184 {
@@ -278,5 +260,20 @@ public override string ToString()
278260 {
279261 return _row . ToString ( ) ;
280262 }
263+
264+ /// <inheritdoc />
265+ IEnumerator IEnumerable . GetEnumerator ( )
266+ {
267+ return ( ( IEnumerable < object > ) this ) . GetEnumerator ( ) ;
268+ }
269+
270+ /// <inheritdoc />
271+ IEnumerator < object > IEnumerable < object > . GetEnumerator ( )
272+ {
273+ for ( int i = 0 ; i < Count ; i ++ )
274+ {
275+ yield return GetObject ( i ) ;
276+ }
277+ }
281278 }
282279}
0 commit comments