PageSCValue.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace MECF.Framework.UI.Core.View.Common
  8. {
  9. public class PageSCValue
  10. {
  11. protected Dictionary<string, PropertyInfo> _fieldMap = new Dictionary<string, PropertyInfo>();
  12. public PageSCValue()
  13. {
  14. }
  15. public List<string> GetKeys()
  16. {
  17. return _fieldMap.Keys.ToList();
  18. }
  19. public void UpdateKeys(PropertyInfo[] property)
  20. {
  21. _fieldMap.Clear();
  22. foreach (PropertyInfo fiGroup in property)
  23. {
  24. _fieldMap[fiGroup.Name.Replace("_", ".")] = fiGroup;
  25. }
  26. }
  27. public void Update(Dictionary<string, object> result)
  28. {
  29. if (result == null)
  30. return;
  31. foreach (KeyValuePair<string, object> item in result)
  32. {
  33. if (_fieldMap.ContainsKey(item.Key))
  34. {
  35. _fieldMap[item.Key].SetValue(this, item.Value, null);
  36. }
  37. }
  38. }
  39. public void Update(string key, string value)
  40. {
  41. if (!_fieldMap.ContainsKey(key))
  42. return;
  43. if (_fieldMap[key].PropertyType == typeof(double))
  44. {
  45. _fieldMap[key].SetValue(this, Convert.ToDouble(value), null);
  46. }
  47. else if (_fieldMap[key].PropertyType == typeof(int))
  48. {
  49. _fieldMap[key].SetValue(this, Convert.ToInt32(value), null);
  50. }
  51. else if (_fieldMap[key].PropertyType == typeof(string))
  52. {
  53. _fieldMap[key].SetValue(this, value, null);
  54. }
  55. else if (_fieldMap[key].PropertyType == typeof(bool))
  56. {
  57. _fieldMap[key].SetValue(this, Convert.ToBoolean(value), null);
  58. }
  59. }
  60. public Dictionary<string, object> GetValue()
  61. {
  62. Dictionary<string, object> result = new Dictionary<string, object>();
  63. foreach (var item in _fieldMap)
  64. {
  65. result[item.Key] = item.Value.GetValue(this, null);
  66. }
  67. return result;
  68. }
  69. }
  70. }