StringExtension.cs 784 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. namespace MySystem
  7. {
  8. public static class StringBuilderExtension
  9. {
  10. public static void Condition(this StringBuilder input, string field, object val)
  11. {
  12. if(typeof(int) == val.GetType() || typeof(decimal) == val.GetType())
  13. {
  14. input.Append(" and " + field + "=" + val);
  15. }
  16. else
  17. {
  18. input.Append(" and " + field + "='" + val + "'");
  19. }
  20. }
  21. public static void ConditionLike(this StringBuilder input, string field, object val)
  22. {
  23. input.Append(" and " + field + " like '%" + val + "%'");
  24. }
  25. }
  26. }