using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace Zhaizj.Framework.ORM { /// /// 验证批注的抽象基类。如果要自定义验证批注,请通过继承此基类扩展 /// [Serializable, AttributeUsage( AttributeTargets.Property )] public abstract class ValidationAttribute : Attribute { private String _message; /// /// 错误提示信息 /// public String Message { get { return _message; } set { _message = value; } } /// /// 多国语言化的错误提示信息 /// public String Lang { set { _message = lang.get( value ); } get { return _message; } } /// /// 可以扩展的验证方法 /// /// 当前操作:update或insert /// 需要验证的实体对象 /// 当前属性信息 /// 验证结果 public abstract void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ); public virtual void Validate( String action, Object target, String propertyName, Result result ) { if (target == null) return; IEntity entity = target as IEntity; if (entity == null) throw new NotImplementedException( "NotNullAttribute can only implement to IEntity. Currenty object's type:" + target.GetType().FullName ); EntityPropertyInfo ep = Entity.GetInfo( entity ).GetProperty( propertyName ); Validate( action, entity, ep, result ); } } }