PageSCValue.cs 2.3 KB

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