protected override void AddValue(string name, object value) { IValueSchema <object> schema = Schemas.SchemaFactory.Create(value.GetType()); schema.Validate(value); _store.Add(name, value); }
/// <summary> /// Runs the validation on the collection /// </summary> public virtual void Validate() { List <string> errors = new List <string>(); IEnumerator <KeyValuePair <string, object> > en = GetEnumerator(); while (en.MoveNext()) { IValueSchema <object> schema = Schemas.GetSchema(en.Current.Key); if (schema == null) { continue; } try { schema.Validate(en.Current.Value); } catch (PropertyValidationException ex) { errors.Add($"{en.Current.Key} {ex.Message}"); } } if (errors.Count > 0) { throw new PropertyValidationException($"Validation errors: {string.Join("\n", errors)}"); } }
/// <summary> /// Gets or sets the element with the specified key. /// </summary> /// <returns> /// The element with the specified key. /// </returns> /// <param name="key">The key of the element to get or set.</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception><exception cref="T:System.Collections.Generic.KeyNotFoundException">The property is retrieved and <paramref name="key"/> is not found.</exception><exception cref="T:System.NotSupportedException">The property is set and the <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.</exception> public override object this[string key] { get { return(_store[key]); } set { IValueSchema <object> schema = Schemas.GetSchema(key); if (schema == null) { schema = Schemas.SchemaFactory.Create(value.GetType()); } schema.Validate(value); _store[key] = value; } }
public void Validate(object value) { _real.Validate(value); }