Exemplo n.º 1
0
    public override Color Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        int c;

        switch (reader.TokenType)
        {
        case JsonTokenType.Number:
        {
            c = reader.GetInt32();
            break;
        }

        case JsonTokenType.String when options.NumberHandling.HasFlag(JsonNumberHandling.AllowReadingFromString):
        {
            c = int.Parse(reader.GetString() !);
            break;
        }

        default:
        {
            throw new JsonException();
        }
        }

        return(Color.FromArgb((int)(c | 0xFF000000)));
    }
Exemplo n.º 2
0
        public override Snowflake Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            switch (reader.TokenType)
            {
            case JsonTokenType.Number:
            {
                return(reader.GetUInt64());
            }

            case JsonTokenType.String when options.NumberHandling.HasFlag(JsonNumberHandling.AllowReadingFromString):
            {
                return(ulong.Parse(reader.GetString() !));
            }

            default:
            {
                throw new JsonException();
            }
            }
        }