DataTableProcessor.DataProcessorUtility.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Reflection;
  11. namespace MetaClient.Editor.DataTableTools
  12. {
  13. public sealed partial class DataTableProcessor
  14. {
  15. private static class DataProcessorUtility
  16. {
  17. private static readonly IDictionary<string, DataProcessor> s_DataProcessors = new SortedDictionary<string, DataProcessor>(StringComparer.Ordinal);
  18. static DataProcessorUtility()
  19. {
  20. System.Type dataProcessorBaseType = typeof(DataProcessor);
  21. Assembly assembly = Assembly.GetExecutingAssembly();
  22. System.Type[] types = assembly.GetTypes();
  23. for (int i = 0; i < types.Length; i++)
  24. {
  25. if (!types[i].IsClass || types[i].IsAbstract)
  26. {
  27. continue;
  28. }
  29. if (dataProcessorBaseType.IsAssignableFrom(types[i]))
  30. {
  31. DataProcessor dataProcessor = (DataProcessor)Activator.CreateInstance(types[i]);
  32. foreach (string typeString in dataProcessor.GetTypeStrings())
  33. {
  34. s_DataProcessors.Add(typeString.ToLowerInvariant(), dataProcessor);
  35. }
  36. }
  37. }
  38. }
  39. public static DataProcessor GetDataProcessor(string type)
  40. {
  41. if (type == null)
  42. {
  43. type = string.Empty;
  44. }
  45. DataProcessor dataProcessor = null;
  46. if (s_DataProcessors.TryGetValue(type.ToLowerInvariant(), out dataProcessor))
  47. {
  48. return dataProcessor;
  49. }
  50. throw new GameFrameworkException(Utility.Text.Format("Not supported data processor type '{0}'.", type));
  51. }
  52. }
  53. }
  54. }