ClassBuilderManager.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. namespace WebAPIBase.NetCore.BusinessCore
  9. {
  10. public sealed class ClassBuilderManager
  11. {
  12. private static Hashtable builderNames = new Hashtable();
  13. public static void LoadClassBuilderDefine()
  14. {
  15. try
  16. {
  17. XmlDocument xmlDoc = XmlDefineFileManage.GetXmlDoc("ClassBuilders");
  18. XmlNodeList xmlNodeList = xmlDoc.DocumentElement.SelectNodes("Class");
  19. int count = xmlNodeList.Count;
  20. for (int i = 0; i < count; i++)
  21. {
  22. XmlNode xmlNode = xmlNodeList.Item(i);
  23. string innerText = xmlNode.Attributes["Name"].InnerText;
  24. string innerText2 = xmlNode.Attributes["Type"].InnerText;
  25. if (builderNames.Contains(innerText))
  26. {
  27. throw new ApplicationException("在ClassBuilders.xml中有重复定义: " + innerText);
  28. }
  29. builderNames.Add(innerText, innerText2);
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. throw ex;
  35. }
  36. }
  37. public static string GetClassBuilderName(string className)
  38. {
  39. try
  40. {
  41. if (!builderNames.Contains(className))
  42. {
  43. throw new ApplicationException("没有在ClassBuilders.xml中定义" + className);
  44. }
  45. return (string)builderNames[className];
  46. }
  47. catch (Exception ex)
  48. {
  49. throw ex;
  50. }
  51. }
  52. }
  53. }