You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.5 KiB
83 lines
1.5 KiB
using System;
|
|
using System.Collections;
|
|
|
|
namespace learun.wechat
|
|
{
|
|
/// <summary>
|
|
/// 版 本 EasyCode EC管理后台
|
|
/// Copyright (c) 2019-present EC管理有限公司
|
|
/// 创建人:tobin
|
|
/// 日 期:2019.11.06
|
|
/// 描 述:不能为空属性
|
|
/// </summary>
|
|
public class IsNotNullAttribute : Attribute, IVerifyAttribute
|
|
{
|
|
private bool IsNotNull { get; set; }
|
|
|
|
private string Message { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public IsNotNullAttribute()
|
|
{
|
|
IsNotNull = true;
|
|
Message = "不能为空";
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="isNotNull"></param>
|
|
public IsNotNullAttribute(bool isNotNull)
|
|
{
|
|
IsNotNull = isNotNull;
|
|
Message = "不能为空";
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="isNull"></param>
|
|
/// <param name="message"></param>
|
|
public IsNotNullAttribute(bool isNull, string message)
|
|
{
|
|
IsNotNull = isNull;
|
|
Message = message;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="obj"></param>
|
|
/// <param name="message"></param>
|
|
/// <returns></returns>
|
|
public bool Verify(Type type, object obj, out string message)
|
|
{
|
|
message = "";
|
|
|
|
if (IsNotNull == false)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (obj == null)
|
|
{
|
|
message = Message;
|
|
return false;
|
|
}
|
|
|
|
if (obj is IList)
|
|
{
|
|
if ((obj as IList).Count <= 0)
|
|
{
|
|
message = Message;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|