public override object ParseLiteral(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is StringValueNode stringLiteral) { if (!NameUtils.IsValidName(stringLiteral.Value)) { throw new ScalarSerializationException( string.Format(CultureInfo.InvariantCulture, AbstractionResources.Type_NameIsNotValid, stringLiteral.Value ?? "null")); } return(new NameString(stringLiteral.Value)); } 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 StringValueNode stringLiteral) { if (!NameUtils.IsValidName(stringLiteral.Value)) { throw new ScalarSerializationException( AbstractionResources.Type_Name_IsNotValid( stringLiteral.Value)); } return(new NameString(stringLiteral.Value)); } if (literal is NullValueNode) { return(null); } throw new ScalarSerializationException( TypeResources.Scalar_Cannot_ParseLiteral( Name, literal.GetType())); }
/// <summary> /// Initializes a new instance of the <see cref="NameString"/> struct. /// </summary> /// <param name="value">The actual type name string</param> /// <exception cref="ArgumentException" public NameString(string value) { if (!NameUtils.IsValidName(value)) { throw new ArgumentException( AbstractionResources.Type_Name_IsNotValid(value), nameof(value)); } Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="NameString"/> struct. /// </summary> /// <param name="value">The actual type name string</param> /// <exception cref="ArgumentException" public NameString(string value) { if (!NameUtils.IsValidName(value)) { throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, AbstractionResources.Type_NameIsNotValid, value ?? "null"), nameof(value)); } Value = value; }
public override bool IsInstanceOfType(IValueNode literal) { if (literal == null) { throw new ArgumentNullException(nameof(literal)); } if (literal is NullValueNode) { return(true); } return(literal is StringValueNode s && NameUtils.IsValidName(s.Value)); }
public void TestInvalid(string name) { Assert.False(NameUtils.IsValidName(name)); }
public void TestValid(string name) { Assert.True(NameUtils.IsValidName(name)); }