86 lines
2.7 KiB
C#
86 lines
2.7 KiB
C#
using Autodesk.Revit.UI;
|
||
using RookieStation.PackAreaModule;
|
||
using RookieStation.UserClient;
|
||
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<DescriptionAttribute>()
|
||
.Cast<DescriptionAttribute>()
|
||
.SingleOrDefault();
|
||
if (descriptionAttr == null)
|
||
{
|
||
return enumObj.ToString();
|
||
}
|
||
else
|
||
{
|
||
return descriptionAttr.Description;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开窗口,解决引用UI库样式丢失,构造函数不具有参数时
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <returns></returns>
|
||
public static T GenerateWindow<T>() 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;
|
||
}
|
||
}
|
||
} |