DataTableTool.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. namespace IFramework.Serialization.DataTable
  7. {
  8. /// <summary>
  9. /// DataTable
  10. /// </summary>
  11. public static class DataTableTool
  12. {
  13. /// <summary>
  14. /// 创建数据读取器
  15. /// </summary>
  16. /// <param name="streamReader"></param>
  17. /// <param name="rowReader"></param>
  18. /// <param name="explainer"></param>
  19. /// <returns></returns>
  20. public static IDataReader CreateReader(TextReader streamReader, IDataRow rowReader, IDataExplainer explainer)
  21. {
  22. return new DataReader(streamReader, rowReader, explainer);
  23. }
  24. /// <summary>
  25. /// 创建数据读取器
  26. /// </summary>
  27. /// <param name="text"></param>
  28. /// <param name="rowReader"></param>
  29. /// <param name="explainer"></param>
  30. /// <returns></returns>
  31. public static IDataReader CreateReader(string text, IDataRow rowReader, IDataExplainer explainer)
  32. {
  33. return new DataReader(text, rowReader, explainer);
  34. }
  35. /// <summary>
  36. /// 创建数据写入器
  37. /// </summary>
  38. /// <param name="streamWriter"></param>
  39. /// <param name="rowWriter"></param>
  40. /// <param name="explainer"></param>
  41. /// <returns></returns>
  42. public static IDataWriter CreateWriter(TextWriter streamWriter, IDataRow rowWriter, IDataExplainer explainer)
  43. {
  44. return new DataWriter( streamWriter, rowWriter, explainer);
  45. }
  46. internal static Dictionary<MemberInfo, string> GetMemberInfo(Type type)
  47. {
  48. Dictionary<MemberInfo, string> members = new Dictionary<MemberInfo, string>();
  49. type.GetFields(/*BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static*/)
  50. .ToList().FindAll((field) => { return !field.IsNotSerialized && !field.IsDefined(typeof(DataIgnoreAttribute), false); ; })
  51. .ForEach((field) => {
  52. if (field.IsDefined(typeof(DataColumnNameAttribute), false))
  53. members.Add(field, (field.GetCustomAttributes(typeof(DataColumnNameAttribute),false)[0]
  54. as DataColumnNameAttribute).name);
  55. else
  56. members.Add(field, field.Name);
  57. });
  58. type.GetProperties(/*BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static*/)
  59. .ToList().FindAll((property) => { return !property.IsDefined(typeof(DataIgnoreAttribute), false) && property.CanWrite && property.CanRead; })
  60. .ForEach((property) => {
  61. if (property.IsDefined(typeof(DataColumnNameAttribute), false))
  62. members.Add(property, (property.GetCustomAttributes(typeof(DataColumnNameAttribute), false)[0]
  63. as DataColumnNameAttribute).name);
  64. else
  65. members.Add(property, property.Name);
  66. });
  67. return members;
  68. }
  69. }
  70. }