protected override NamedId <string> ReadValue(JsonReader reader, Type objectType, JsonSerializer serializer) { var value = serializer.Deserialize <string>(reader) !; if (!NamedId <string> .TryParse(value, ParseString, out var result)) { throw new JsonException("Named id must have at least 2 parts divided by commata."); } return(result); }
protected override NamedId <long> ReadValue(JsonReader reader, Type objectType, JsonSerializer serializer) { if (reader.TokenType != JsonToken.String) { throw new JsonException($"Expected String, but got {reader.TokenType}."); } if (!NamedId <long> .TryParse(reader.Value.ToString(), long.TryParse, out var result)) { throw new JsonException("Named id must have at least 2 parts divided by commata."); } return(result); }
private bool TryGenerateNewNamedId(string value, out string result) { if (value.Length > GuidLength) { if (strings.TryGetValue(value, out result)) { return(true); } if (NamedId <Guid> .TryParse(value, Guid.TryParse, out var namedId)) { var newGuid = GenerateNewGuid(namedId.Id); strings[value] = result = new NamedId <Guid>(newGuid, namedId.Name).ToString(); return(true); } } result = null; return(false); }