@@ -36,20 +36,43 @@ public record class ApiEnum<TRaw, TEnum>(JsonElement Json)
3636 /// <see cref="Json"/> to access the raw value.
3737 /// </exception>
3838 /// </summary>
39- public TRaw Raw ( ) =>
40- JsonSerializer . Deserialize < TRaw > ( this . Json , ModelBase . SerializerOptions )
41- ?? throw new OrbInvalidDataException (
42- string . Format ( "{0} cannot be null" , nameof ( this . Json ) )
43- ) ;
39+ public TRaw Raw ( )
40+ {
41+ try
42+ {
43+ return JsonSerializer . Deserialize < TRaw > ( this . Json , ModelBase . SerializerOptions )
44+ ?? throw new OrbInvalidDataException ( $ "{ nameof ( this . Json ) } cannot be null") ;
45+ }
46+ catch ( JsonException e )
47+ {
48+ throw new OrbInvalidDataException (
49+ $ "{ this . Json } must be of type { typeof ( TRaw ) . FullName } ",
50+ e
51+ ) ;
52+ }
53+ }
4454
4555 /// <summary>
4656 /// Returns an enum member corresponding to this instance's value, or <c>(TEnum)(-1)</c> if the
4757 /// class was instantiated with an unknown value.
4858 ///
4959 /// <para>Use <see cref="Raw"/> to access the raw <typeparamref name="TRaw"/> value.</para>.
5060 /// </summary>
51- public TEnum Value ( ) =>
52- JsonSerializer . Deserialize < TEnum > ( this . Json , ModelBase . SerializerOptions ) ;
61+ public TEnum Value ( )
62+ {
63+ try
64+ {
65+ return JsonSerializer . Deserialize < TEnum ? > ( this . Json , ModelBase . SerializerOptions )
66+ ?? throw new OrbInvalidDataException ( $ "{ nameof ( this . Json ) } cannot be null") ;
67+ }
68+ catch ( JsonException e )
69+ {
70+ throw new OrbInvalidDataException (
71+ $ "{ this . Json } must be of type { typeof ( TRaw ) . FullName } ",
72+ e
73+ ) ;
74+ }
75+ }
5376
5477 /// <summary>
5578 /// Verifies that this instance's raw value is a member of <typeparamref name="TEnum"/>.
0 commit comments