public override object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is StringValueNode stringLiteral) { return(stringLiteral.Value); } if (literal is IntValueNode intLiteral) { return(intLiteral.Value); } if (literal is NullValueNode) { return(null); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
public object?ParseLiteral(IValueNode valueSyntax, bool withDefaults = true) { if (valueSyntax is null) { throw new ArgumentNullException(nameof(valueSyntax)); } if (valueSyntax is EnumValueNode evn && _enumValues.TryGetValue(evn.Value, out IEnumValue? ev)) { return(ev.Value); } if (valueSyntax is StringValueNode svn && _enumValues.TryGetValue(svn.Value, out ev)) { return(ev.Value); } if (valueSyntax is NullValueNode) { return(null); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
public override object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is StringValueNode stringLiteral) { if (!MultiplierPathString.IsValidName(stringLiteral.Value)) { throw new ScalarSerializationException( string.Format(CultureInfo.InvariantCulture, AbstractionResources.Type_NameIsNotValid, stringLiteral.Value ?? "null")); } return(new MultiplierPathString(stringLiteral.Value)); } if (literal is NullValueNode) { return(null); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
public override object ParseLiteral(IValueNode literal, bool withDefaults = true) { switch (literal) { case StringValueNode svn: return(svn.Value); case IntValueNode ivn: return(long.Parse(ivn.Value, CultureInfo.InvariantCulture)); case FloatValueNode fvn: return(decimal.Parse(fvn.Value, CultureInfo.InvariantCulture)); case BooleanValueNode bvn: return(bvn.Value); case ListValueNode lvn: return(_objectValueToDictConverter.Convert(lvn)); case ObjectValueNode ovn: return(_objectValueToDictConverter.Convert(ovn)); case NullValueNode _: return(null); default: throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, literal.GetType()), this); } }
public override object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is IntValueNode intLiteral && int.TryParse( intLiteral.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int i) && i >= _min && i <= _max) { return(i); } if (literal is NullValueNode) { return(null); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
public override object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is NullValueNode) { return(null); } if (literal is FloatValueNode floatLiteral && TryParseDecimal(floatLiteral.Value, out var d)) { return(d); } if (literal is IntValueNode intLiteral && TryParseDecimal(intLiteral.Value, out d)) { return(d); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
public override object?ParseLiteral(IValueNode valueSyntax, bool withDefaults = true) { if (valueSyntax is null) { throw new ArgumentNullException(nameof(valueSyntax)); } if (valueSyntax is NullValueNode) { return(null); } if (valueSyntax is FloatValueNode floatLiteral) { return(ParseLiteral(floatLiteral)); } // Input coercion rules specify that float values can be coerced // from IntValueNode and FloatValueNode: // http://facebook.github.io/graphql/June2018/#sec-Float if (valueSyntax is IntValueNode intLiteral) { return(ParseLiteral(intLiteral)); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
protected sealed override object?ParseLiteral(IValueNode valueSyntax, bool withDefaults) { if (valueSyntax is NullValueNode) { return(null); } if (valueSyntax.Kind != SyntaxKind.ListValue && InnerInputType !.IsInstanceOfType(valueSyntax)) { return(CreateList(new ListValueNode(valueSyntax), withDefaults)); } if (valueSyntax.Kind == SyntaxKind.ListValue) { if (_isNestedList) { if (IsInstanceOfType(valueSyntax)) { return(CreateList((ListValueNode)valueSyntax, withDefaults)); } } else { return(CreateList((ListValueNode)valueSyntax, withDefaults)); } } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(this.Print(), valueSyntax.GetType()), this); }
public override object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is NullValueNode) { return(null); } if (literal is FloatValueNode floatLiteral && TryParseDouble(floatLiteral.Value, out double d)) { return(d); } // Input coercion rules specify that float values can be coerced // from IntValueNode and FloatValueNode: // http://facebook.github.io/graphql/June2018/#sec-Float if (literal is IntValueNode intLiteral && TryParseDouble(intLiteral.Value, out d)) { return(d); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
protected override NameString ParseLiteral(StringValueNode valueSyntax) { if (IsInstanceOfType(valueSyntax)) { return(new NameString(valueSyntax.Value)); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
protected override DateTime ParseLiteral(StringValueNode valueSyntax) { if (TryDeserializeFromString(valueSyntax.Value, out DateTime? value)) { return(value.Value); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
protected override DateTimeOffset ParseLiteral(StringValueNode literal) { if (TryDeserializeFromString(literal.Value, out DateTimeOffset? value)) { return(value.Value); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
protected override NameString ParseLiteral(StringValueNode literal) { if (IsInstanceOfType(literal)) { return(new NameString(literal.Value)); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
protected override Guid ParseLiteral(StringValueNode valueSyntax) { if (Utf8Parser.TryParse(valueSyntax.AsSpan(), out Guid g, out _, _format[0])) { return(g); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
protected override Uri ParseLiteral(StringValueNode valueSyntax) { if (TryParseUri(valueSyntax.Value, out Uri uri)) { return(uri); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
protected override Guid ParseLiteral(StringValueNode literal) { if (Utf8Parser.TryParse(literal.AsSpan(), out Guid g, out int _, _format)) { return(g); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
protected override Uri ParseLiteral(StringValueNode literal) { if (TryParseUri(literal.Value, out Uri uri)) { return(uri); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
protected override TimeSpan ParseLiteral(StringValueNode valueSyntax) { if (TryDeserializeFromString(valueSyntax.Value, _format, out TimeSpan? value) && value != null) { return(value.Value); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
public override IValueNode ParseResult(object?resultValue) { if (resultValue is null) { return(NullValueNode.Default); } if (resultValue is string s) { return(new StringValueNode(s)); } if (resultValue is Guid g) { return(ParseValue(g)); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, resultValue.GetType()), this); }
public sealed override object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is TLiteral casted && IsInstanceOfType(casted)) { return(ParseLiteral(casted)); } if (literal is NullValueNode) { return(null); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
public sealed override object?ParseLiteral( IValueNode valueSyntax, bool withDefaults = true) { if (valueSyntax is null) { throw new ArgumentNullException(nameof(valueSyntax)); } if (valueSyntax is TLiteral casted && IsInstanceOfType(casted)) { return(ParseLiteral(casted)); } if (valueSyntax is NullValueNode) { return(null); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this); }
public object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is EnumValueNode evn && _nameToValues.TryGetValue(evn.Value, out EnumValue ev)) { return(ev.Value); } if (literal is NullValueNode) { return(null); } throw new ArgumentException( TypeResourceHelper.Scalar_Cannot_ParseLiteral( Name, literal.GetType()), nameof(literal)); }
protected virtual SerializationException CreateParseLiteralError(IValueNode valueSyntax) { return(new( TypeResourceHelper.Scalar_Cannot_ParseLiteral(Name, valueSyntax.GetType()), this)); }