Esempio n. 1
0
        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()));
        }
Esempio n. 2
0
        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()));
        }
Esempio n. 3
0
 /// <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;
 }
Esempio n. 4
0
 /// <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;
 }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
 public void TestInvalid(string name)
 {
     Assert.False(NameUtils.IsValidName(name));
 }
Esempio n. 7
0
 public void TestValid(string name)
 {
     Assert.True(NameUtils.IsValidName(name));
 }