src/StarCitizen-API-Wrapper.Models/JsonConverters/Int/StringToNullableIntConverter.cs
/// <summary>
/// Tries to convert the given json value into a nullable int.
/// Otherwise throws.
/// </summary>
Tries to convert the given json value into a nullable int.
Otherwise throws.
Tries to convert the given json value into a nullable int . Otherwise throws .
public override int? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            var stringValue = reader.GetString();
            if (string.IsNullOrWhiteSpace(stringValue))
                return null;
            if (int.TryParse(stringValue, out var result))
                return result;
            try
            {
                return reader.GetInt32();
            }
            catch (Exception e)
            {
                Debug.Fail(e.Message);
                throw;
            }
        }
public override int ? Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options ) { var stringValue = reader . GetString ( ) ; if ( string . IsNullOrWhiteSpace ( stringValue ) ) return null ; if ( int . TryParse ( stringValue , out var result ) ) return result ; try { return reader . GetInt32 ( ) ; } catch ( Exception e ) { Debug . Fail ( e . Message ) ; throw ; } }
Tries to convert the given json value into a nullable int.
Tries to convert the given json value into a nullable int .
Utf8JsonReader
ref
typeToConvert
Type
options
JsonSerializerOptions