/////////////////////////////////////////////////////////////////////////////
|
// File Description : 验证实体类
|
// Copyright : joyin
|
// -------------------------------------------------------------------------
|
// Date Created : Mar 26, 2010
|
// Author : jiangxinjun
|
//
|
/////////////////////////////////////////////////////////////////////////////
|
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace HH.WMS.Entitys.Common
|
{
|
/// <summary>
|
/// 验证实体类
|
/// </summary>
|
/// <typeparam name="TEntity">需要验证的实体类类型</typeparam>
|
public class ValidatorEntity<TEntity>
|
{
|
private TEntity entity;
|
|
private List<string> errorMsgs;
|
|
/// <summary>
|
/// 错误信息
|
/// </summary>
|
public List<string> ErrorMessages
|
{
|
get
|
{
|
if (errorMsgs == null)
|
{
|
errorMsgs = new List<string>();
|
}
|
return errorMsgs;
|
}
|
}
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="entity"></param>
|
public ValidatorEntity(TEntity entity)
|
{
|
this.entity = entity;
|
}
|
|
/// <summary>
|
/// 验证
|
/// </summary>
|
/// <param name="predicate">错误成立条件</param>
|
/// <param name="errorMsg">如果错误成立,显示的错误信息</param>
|
/// <returns></returns>
|
public ValidatorEntity<TEntity> Validate(Predicate<TEntity> predicate, string errorMsg)
|
{
|
if (predicate != null && predicate(entity))
|
{
|
this.ErrorMessages.Add(errorMsg);
|
}
|
return this;
|
}
|
}
|
}
|