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.
 
 
 
 
 
 

58 lines
1.2 KiB

  1. using System;
  2. using System.Collections;
  3. namespace Learun.Application.WeChat
  4. {
  5. public class IsNotNullAttribute : System.Attribute, IVerifyAttribute
  6. {
  7. bool IsNotNull { get; set; }
  8. string Message { get; set; }
  9. public IsNotNullAttribute()
  10. {
  11. IsNotNull = true;
  12. Message = "不能为空";
  13. }
  14. public IsNotNullAttribute(bool isNotNull)
  15. {
  16. IsNotNull = isNotNull;
  17. Message = "不能为空";
  18. }
  19. public IsNotNullAttribute(bool isNull, string message)
  20. {
  21. IsNotNull = isNull;
  22. Message = message;
  23. }
  24. public bool Verify(Type type, object obj, out string message)
  25. {
  26. message = "";
  27. if (IsNotNull == false)
  28. {
  29. return true;
  30. }
  31. if (obj == null)
  32. {
  33. message = Message;
  34. return false;
  35. }
  36. if (obj is IList)
  37. {
  38. if ((obj as IList).Count <= 0)
  39. {
  40. message = Message;
  41. return false;
  42. }
  43. }
  44. return true;
  45. }
  46. }
  47. }