You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldValue.cs
+17-6Lines changed: 17 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -222,6 +222,7 @@ public string AsString()
222
222
thrownewInvalidOperationException($"Cannot get field as String. Field value's type is {ValueType}.");
223
223
}
224
224
225
+
// Use when mocking
225
226
if(_fieldValue==null)
226
227
{
227
228
returnValueString;
@@ -242,14 +243,15 @@ public long AsInt64()
242
243
thrownewInvalidOperationException($"Cannot get field as Integer. Field value's type is {ValueType}.");
243
244
}
244
245
246
+
// Use when mocking
245
247
if(_fieldValue==null)
246
248
{
247
249
returnValueInteger;
248
250
}
249
251
250
252
if(!_fieldValue.ValueInteger.HasValue)
251
253
{
252
-
thrownewInvalidOperationException($"Not able to parse to {nameof(FieldValueType.Int64)} type. Consider using the 'ValueData.Text' property.");
254
+
thrownewInvalidOperationException($"Value was extracted from the form, but cannot be normalized to {nameof(FieldValueType.Int64)} type. Consider accessing the `ValueData.text` property for a textual representation of the value.");
253
255
}
254
256
255
257
return_fieldValue.ValueInteger.Value;
@@ -267,6 +269,7 @@ public float AsFloat()
267
269
thrownewInvalidOperationException($"Cannot get field as Float. Field value's type is {ValueType}.");
268
270
}
269
271
272
+
// Use when mocking
270
273
if(_fieldValue==null)
271
274
{
272
275
returnValueNumber;
@@ -281,7 +284,7 @@ public float AsFloat()
281
284
}
282
285
else
283
286
{
284
-
thrownewInvalidOperationException($"Not able to parse to {nameof(FieldValueType.Float)} type. Consider using the 'ValueData.Text' property.");
287
+
thrownewInvalidOperationException($"Value was extracted from the form, but cannot be normalized to {nameof(FieldValueType.Float)} type. Consider accessing the `ValueData.text` property for a textual representation of the value.");
285
288
}
286
289
}
287
290
@@ -300,14 +303,15 @@ public DateTime AsDate()
300
303
thrownewInvalidOperationException($"Cannot get field as Date. Field value's type is {ValueType}.");
301
304
}
302
305
306
+
// Use when mocking
303
307
if(_fieldValue==null)
304
308
{
305
309
returnValueDate;
306
310
}
307
311
308
312
if(!_fieldValue.ValueDate.HasValue)
309
313
{
310
-
thrownewInvalidOperationException($"Not able to parse to {nameof(FieldValueType.Date)} type. Consider using the 'ValueData.Text' property.");
314
+
thrownewInvalidOperationException($"Value was extracted from the form, but cannot be normalized to {nameof(FieldValueType.Date)} type. Consider accessing the `ValueData.text` property for a textual representation of the value.");
311
315
}
312
316
313
317
return_fieldValue.ValueDate.Value.UtcDateTime;
@@ -325,14 +329,15 @@ public TimeSpan AsTime()
325
329
thrownewInvalidOperationException($"Cannot get field as Time. Field value's type is {ValueType}.");
326
330
}
327
331
332
+
// Use when mocking
328
333
if(_fieldValue==null)
329
334
{
330
335
returnValueTime;
331
336
}
332
337
333
338
if(!_fieldValue.ValueTime.HasValue)
334
339
{
335
-
thrownewInvalidOperationException($"Not able to parse to {nameof(FieldValueType.Time)} type. Consider using the 'ValueData.Text' property.");
340
+
thrownewInvalidOperationException($"Value was extracted from the form, but cannot be normalized to {nameof(FieldValueType.Time)} type. Consider accessing the `ValueData.text` property for a textual representation of the value.");
336
341
}
337
342
338
343
return_fieldValue.ValueTime.Value;
@@ -350,6 +355,7 @@ public string AsPhoneNumber()
350
355
thrownewInvalidOperationException($"Cannot get field as PhoneNumber. Field value's type is {ValueType}.");
351
356
}
352
357
358
+
// Use when mocking
353
359
if(_fieldValue==null)
354
360
{
355
361
returnValueString;
@@ -370,6 +376,7 @@ public IReadOnlyList<FormField> AsList()
370
376
thrownewInvalidOperationException($"Cannot get field as List. Field value's type is {ValueType}.");
371
377
}
372
378
379
+
// Use when mocking
373
380
if(_fieldValue==null)
374
381
{
375
382
returnValueList;
@@ -396,6 +403,7 @@ public IReadOnlyDictionary<string, FormField> AsDictionary()
396
403
thrownewInvalidOperationException($"Cannot get field as Dictionary. Field value's type is {ValueType}.");
397
404
}
398
405
406
+
// Use when mocking
399
407
if(_fieldValue==null)
400
408
{
401
409
returnValueDictionary;
@@ -430,14 +438,15 @@ public SelectionMarkState AsSelectionMarkState()
430
438
thrownewInvalidOperationException($"Cannot get field as SelectionMark. Field value's type is {ValueType}.");
431
439
}
432
440
441
+
// Use when mocking
433
442
if(_fieldValue==null)
434
443
{
435
444
returnValueSelectionMark;
436
445
}
437
446
438
447
if(!_fieldValue.ValueSelectionMark.HasValue)
439
448
{
440
-
thrownewInvalidOperationException($"Not able to parse to {nameof(FieldValueType.SelectionMark)} type. Consider using the 'ValueData.Text' property.");
449
+
thrownewInvalidOperationException($"Value was extracted from the form, but cannot be normalized to {nameof(FieldValueType.SelectionMark)} type. Consider accessing the `ValueData.text` property for a textual representation of the value.");
441
450
}
442
451
443
452
return_fieldValue.ValueSelectionMark.Value;
@@ -455,6 +464,7 @@ public string AsCountryCode()
455
464
thrownewInvalidOperationException($"Cannot get field as country code. Field value's type is {ValueType}.");
456
465
}
457
466
467
+
// Use when mocking
458
468
if(_fieldValue==null)
459
469
{
460
470
returnValueString;
@@ -475,14 +485,15 @@ public FieldValueGender AsGender()
475
485
thrownewInvalidOperationException($"Cannot get field as gender. Field value's type is {ValueType}.");
476
486
}
477
487
488
+
// Use when mocking
478
489
if(_fieldValue==null)
479
490
{
480
491
returnValueGender;
481
492
}
482
493
483
494
if(!_fieldValue.ValueGender.HasValue)
484
495
{
485
-
thrownewInvalidOperationException($"Not able to parse to {nameof(FieldValueType.Gender)} type. Consider using the 'ValueData.Text' property.");
496
+
thrownewInvalidOperationException($"Value was extracted from the form, but cannot be normalized to {nameof(FieldValueType.Gender)} type. Consider accessing the `ValueData.text` property for a textual representation of the value.");
0 commit comments