using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Abp.Collections.Extensions; namespace Abp.Runtime.Validation { [Serializable] public abstract class ValueValidatorBase : IValueValidator { public virtual string Name { get { var type = GetType().GetTypeInfo(); if (type.IsDefined(typeof(ValidatorAttribute))) { return type.GetCustomAttributes(typeof(ValidatorAttribute)).Cast().First().Name; } return type.Name; } } /// /// Gets/sets arbitrary objects related to this object. /// Gets null if given key does not exists. /// /// Key public object this[string key] { get { return Attributes.GetOrDefault(key); } set { Attributes[key] = value; } } /// /// Arbitrary objects related to this object. /// public IDictionary Attributes { get; private set; } public abstract bool IsValid(object value); protected ValueValidatorBase() { Attributes = new Dictionary(); } } }