ApiParameters.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // DtkSDK.ApiParameters
  2. using System.Collections.Generic;
  3. namespace Dataoke
  4. {
  5. public class ApiParameters
  6. {
  7. private List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>();
  8. public List<KeyValuePair<string, string>> Value => parameters;
  9. public void Add(string key, string value)
  10. {
  11. parameters.Add(new KeyValuePair<string, string>(key, value));
  12. }
  13. public bool Delete(string key)
  14. {
  15. try
  16. {
  17. int find = parameters.FindIndex((KeyValuePair<string, string> a) => a.Key == key);
  18. if (find >= 0)
  19. {
  20. parameters.RemoveAt(find);
  21. }
  22. return true;
  23. }
  24. catch
  25. {
  26. return false;
  27. }
  28. }
  29. public bool EditOrAdd(string key, string value)
  30. {
  31. try
  32. {
  33. int find = parameters.FindIndex((KeyValuePair<string, string> a) => a.Key == key);
  34. if (find >= 0)
  35. {
  36. parameters.RemoveAt(find);
  37. }
  38. Add(key, value);
  39. return true;
  40. }
  41. catch
  42. {
  43. return false;
  44. }
  45. }
  46. public bool Edit(string key, string value)
  47. {
  48. try
  49. {
  50. int find = parameters.FindIndex((KeyValuePair<string, string> a) => a.Key == key);
  51. if (find >= 0)
  52. {
  53. parameters.RemoveAt(find);
  54. Add(key, value);
  55. }
  56. return true;
  57. }
  58. catch
  59. {
  60. return false;
  61. }
  62. }
  63. public void Clear()
  64. {
  65. parameters.Clear();
  66. }
  67. }
  68. }