using Autodesk.Revit.UI; using RookieStation.PackAreaModule; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace RookieStation.Utils { internal static class CommonUtils { public static String GetEnumDescription(this Type e, int? value) { FieldInfo[] fields = e.GetFields(); for (int i = 1, count = fields.Length; i < count; i++) { if ((int)System.Enum.Parse(e, fields[i].Name) == value) { DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])fields[i]. GetCustomAttributes(typeof(DescriptionAttribute), false); if (EnumAttributes.Length > 0) { return EnumAttributes[0].Description; } } } return ""; } public static string GetEnumDescription(Enum enumObj) { FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString()); var descriptionAttr = fieldInfo .GetCustomAttributes(false) .OfType() .Cast() .SingleOrDefault(); if (descriptionAttr == null) { return enumObj.ToString(); } else { return descriptionAttr.Description; } } /// /// 打开窗口,解决引用UI库样式丢失 /// /// /// public static T GenerateWindow() where T : System.Windows.Window, new() { string AddInPath = typeof(RsApp).Assembly.Location; string dirAssembly = System.IO.Path.GetDirectoryName(AddInPath); AssemblyLoader loader = new AssemblyLoader(dirAssembly); T win = null; try { loader.HookAssemblyResolve(); win = new T(); System.Windows.Interop.WindowInteropHelper mainUI = new System.Windows.Interop.WindowInteropHelper(win) { Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle }; win.ShowDialog(); } catch (Exception ex) { Log.WriteLog(ex.Message); } finally { loader.UnhookAssemblyResolve(); } return win; } } }