BasicUserData.MaxAge is null

Sep 10, 2011 at 9:29 PM

An exception was thrown when I tried to query the int MaxAge value. This is a typical IsNull issue where no value means there is no max. But that doesn't work with a non-nullable int value.  To avoid the error I've modified the getter as below. My theory on this is that if there  is no maximum age then the max should be 999. We could try -1 or even changing the type to nullable int, but, that's a breaking change that some people might not want to accept. Anyone want to propose something better?

public int MaxAge
{
    get
    {
        try
        {
            JsonObject age = (JsonObject) data[ "age" ];
            if ( age == null )
                return 999;
            if ( age[ "max" ] == null ) // redundant with catch but explicit
                return 999;
            return (int) age[ "max" ];
        }
        catch
        {
            return 999;
        }
    }
}