InEnumUtil.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using FWindSoft.SystemExtensions;
  2. using System;
  3. using System.Linq;
  4. using System.Reflection;
  5. namespace FWindSoft.Revit.ExtensibleStorage
  6. {
  7. /// <summary>
  8. /// 内部应用
  9. /// </summary>
  10. internal class InEnumUtil
  11. {
  12. /// <summary>
  13. /// 获取枚举的guid
  14. /// </summary>
  15. /// <param name="en"></param>
  16. /// <returns></returns>
  17. public static Guid GetGuid(Enum en)
  18. {
  19. var type = en.GetType();
  20. string allPath = type.FullName + en.ToString();
  21. return allPath.ToGuid();
  22. }
  23. internal static SchemaItem CreateSchemaItem(Enum en)
  24. {
  25. SchemaItem item = new SchemaItem();
  26. FieldInfo fieldInfo = en.GetType().GetField(en.ToString());
  27. var fileNameAttribute = fieldInfo.GetCustomAttribute<StorageFileNameAttribute>();
  28. item.FileName = fileNameAttribute?.Name?? en.ToString();
  29. var schemeNameAttribute = fieldInfo.GetCustomAttribute<StorageSchemeNameAttribute>();
  30. item.SchemaName = schemeNameAttribute?.Name ?? en.ToString();
  31. var schemeGuidAttribute = fieldInfo.GetCustomAttribute<StorageSchemeGuidAttribute>();
  32. if (schemeGuidAttribute?.Guid == null)
  33. {
  34. item.SchemaGuid = GetGuid(en);
  35. }
  36. else
  37. {
  38. item.SchemaGuid = new Guid(schemeGuidAttribute?.Guid);
  39. }
  40. return item;
  41. }
  42. }
  43. }