public sealed override IValueNode ParseValue(object value) { if (TryParseValue(value, out IValueNode valueNode)) { return(valueNode); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public override IValueNode ParseValue(object value) { if (value == null) { return(new NullValueNode(null)); } if (value is Guid guid) { return(new StringValueNode(guid.ToString("N"))); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public override IValueNode ParseValue(object value) { if (value is null) { return(NullValueNode.Default); } if (value is int i && i >= _min && i <= _max) { return(new IntValueNode(i)); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public override IValueNode ParseValue(object value) { if (value == null) { return(new NullValueNode(null)); } if (value is MultiplierPathString n) { return(new StringValueNode(null, n, false)); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public IValueNode ParseValue(object?runtimeValue) { if (runtimeValue is null) { return(NullValueNode.Default); } if (_valueLookup.TryGetValue(runtimeValue, out IEnumValue? enumValue)) { return(new EnumValueNode(enumValue.Name)); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue(Name, runtimeValue.GetType()), this); }
public override IValueNode ParseValue(object value) { if (value is null) { return(NullValueNode.Default); } if (value is double d) { return(new FloatValueNode(SerializeDouble(d))); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public sealed override IValueNode ParseValue(object?runtimeValue) { if (runtimeValue is null) { return(NullValueNode.Default); } if (runtimeValue is TRuntimeType t && IsInstanceOfType(t)) { return(ParseValue(t)); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue(Name, runtimeValue.GetType()), this); }
public override IValueNode ParseValue(object?runtimeValue) { if (runtimeValue is null) { return(NullValueNode.Default); } if (runtimeValue is string s) { return(new StringValueNode(s)); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue(Name, runtimeValue.GetType()), this); }
public override IValueNode ParseValue(object value) { if (value is null) { return(NullValueNode.Default); } if (value is bool b) { return(new BooleanValueNode(b)); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public override IValueNode ParseValue(object value) { if (value is null) { return(NullValueNode.Default); } if (value is TClrType casted && IsInstanceOfType(casted)) { return(ParseValue(casted)); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public override IValueNode ParseValue(object value) { if (value == null) { return(new NullValueNode(null)); } if (value is Uri uri) { return(new StringValueNode(uri.AbsoluteUri)); } throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType())); }
public IValueNode ParseValue(object value) { if (value == null) { return(NullValueNode.Default); } if (_valueToValues.TryGetValue(value, out EnumValue enumValue)) { return(new EnumValueNode(enumValue.Name)); } throw new ArgumentException( TypeResourceHelper.Scalar_Cannot_ParseValue( Name, value.GetType()), nameof(value)); }
protected sealed override IValueNode ParseValue(object?runtimeValue) { if (runtimeValue is null) { return(NullValueNode.Default); } if (runtimeValue is IList l) { var items = new List <IValueNode>(); for (var i = 0; i < l.Count; i++) { items.Add(InnerInputType !.ParseValue(l[i])); } return(new ListValueNode(null, items)); } throw new SerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue(this.Print(), runtimeValue.GetType()), this); }
protected sealed override IValueNode ParseValue(object value) { if (value == null) { return(NullValueNode.Default); } if (value is IList l) { var items = new List <IValueNode>(); for (int i = 0; i < l.Count; i++) { items.Add(InnerInputType.ParseValue(l[i])); } return(new ListValueNode(null, items)); } // TODO : resources throw new ScalarSerializationException( TypeResourceHelper.Scalar_Cannot_ParseValue( this.Visualize(), value.GetType())); }
protected virtual SerializationException CreateParseValueError(object runtimeValue) { return(new( TypeResourceHelper.Scalar_Cannot_ParseValue(Name, runtimeValue.GetType()), this)); }