LianLianPayDictionary.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Essensoft.AspNetCore.Payment.LianLianPay
  4. {
  5. /// <summary>
  6. /// LianLianPay 字典。
  7. /// </summary>
  8. public class LianLianPayDictionary : SortedDictionary<string, string>
  9. {
  10. private const string DATE_TIME_FORMAT = "yyyyMMddHHmmss";
  11. public LianLianPayDictionary() { }
  12. public LianLianPayDictionary(IDictionary<string, string> dictionary)
  13. : base(dictionary)
  14. { }
  15. public void Add(string key, object value)
  16. {
  17. string strValue;
  18. if (value == null)
  19. {
  20. strValue = null;
  21. }
  22. else if (value is string)
  23. {
  24. strValue = (string)value;
  25. }
  26. else if (value is DateTime?)
  27. {
  28. var dateTime = value as DateTime?;
  29. strValue = dateTime.Value.ToString(DATE_TIME_FORMAT);
  30. }
  31. else if (value is int?)
  32. {
  33. strValue = (value as int?).Value.ToString();
  34. }
  35. else if (value is long?)
  36. {
  37. strValue = (value as long?).Value.ToString();
  38. }
  39. else if (value is double?)
  40. {
  41. strValue = (value as double?).Value.ToString();
  42. }
  43. else if (value is bool?)
  44. {
  45. strValue = (value as bool?).Value.ToString().ToLower();
  46. }
  47. else
  48. {
  49. strValue = value.ToString();
  50. }
  51. Add(key, strValue);
  52. }
  53. public new void Add(string key, string value)
  54. {
  55. if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
  56. {
  57. base.Add(key, value);
  58. }
  59. }
  60. }
  61. }