/// <summary>
        /// Adds the specified name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">The name.</param>
        /// <param name="schema">The schema.</param>
        /// <returns></returns>
        public virtual T?Add <T>(string name, IValueSchema <T?> schema) where T : struct
        {
            if (IsReadOnly)
            {
                throw new ArgumentException("The collection is read-only.");
            }
            if (ContainsKey(name))
            {
                throw new ArgumentException($"The property name {name} already exist.");
            }
            T?retValue;

            if (schema.HasDefault)
            {
                retValue = schema.DefaultValue;
            }
            else
            {
                if (!schema.AllowNull)
                {
                    throw new ArgumentException($"Null value is not allowed for {name}");
                }
                retValue = default(T?);
            }
            AddWithSchema(name, retValue, schema.Wrap());
            return(retValue);
        }
        /// <summary>
        /// Adds the specified name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">The name.</param>
        /// <param name="schema">The schema.</param>
        /// <returns></returns>
        public virtual T Add <T>(string name, IValueSchema <T> schema) where T : class
        {
            if (IsReadOnly)
            {
                throw new ArgumentException("The collection is read-only.");
            }

            if (ContainsKey(name))
            {
                throw new ArgumentException(string.Format("The property name {0} already exist.", name));
            }
            T value;

            if (schema.HasDefault)
            {
                value = schema.DefaultValue;
            }
            else
            {
                if (!schema.AllowNull)
                {
                    throw new ArgumentException(string.Format("Null value is not allowed for {0}", name));
                }
                value = null;
            }
            AddWithSchema(name, value, schema.Wrap());
            return(value);
        }
        /// <summary>
        /// Adds the specified name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <param name="schema">The schema.</param>
        /// <returns></returns>
        public virtual T?Add <T>(string name, T?value, IValueSchema <T?> schema) where T : struct
        {
            if (IsReadOnly)
            {
                throw new ArgumentException("The collection is read-only.");
            }

            if (ContainsKey(name))
            {
                throw new ArgumentException($"The property name {name} already exist.");
            }
            if (value == null && !schema.AllowNull)
            {
                throw new ArgumentException($"Null value is not allowed for {name}");
            }
            AddWithSchema(name, value, schema.Wrap());
            return(value);
        }
        /// <summary>
        /// Sets the schema for a structure property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">The name.</param>
        /// <param name="schema">The schema.</param>
        public void SetSchema <T>(string name, IValueSchema <T?> schema) where T : struct
        {
            IValueSchema <object> wrapped = schema.Wrap();

            OnSetSchema(name, wrapped);
        }
示例#5
0
 /// <summary>
 /// Wrap a valut type schema
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="schema">The schema.</param>
 public void Visit <T>(IValueSchema <T?> schema) where T : struct
 {
     Schema = schema.Wrap();
 }
示例#6
0
 /// <summary>
 /// Wrap a reference schema
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="schema">The schema.</param>
 public void Visit <T>(IValueSchema <T> schema) where T : class
 {
     Schema = schema.Wrap();
 }