mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 05:34:48 +00:00
implement enum for types, implement OpenDialog from Dialog-API
This commit is contained in:
34
ElectronNET.API/Extensions/EnumExtensions.cs
Normal file
34
ElectronNET.API/Extensions/EnumExtensions.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ElectronNET.API.Extensions
|
||||
{
|
||||
internal static class EnumExtensions
|
||||
{
|
||||
public static string GetDescription<T>(this T enumerationValue) where T : struct
|
||||
{
|
||||
Type type = enumerationValue.GetType();
|
||||
if (!type.IsEnum)
|
||||
{
|
||||
throw new ArgumentException("EnumerationValue must be of Enum type", "enumerationValue");
|
||||
}
|
||||
|
||||
//Tries to find a DescriptionAttribute for a potential friendly name
|
||||
//for the enum
|
||||
MemberInfo[] memberInfo = type.GetMember(enumerationValue.ToString());
|
||||
if (memberInfo != null && memberInfo.Length > 0)
|
||||
{
|
||||
object[] attrs = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
|
||||
if (attrs != null && attrs.Length > 0)
|
||||
{
|
||||
//Pull out the description value
|
||||
return ((DescriptionAttribute)attrs[0]).Description;
|
||||
}
|
||||
}
|
||||
//If we have no description attribute, just return the ToString of the enum
|
||||
return enumerationValue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,7 @@ namespace ElectronNET.API.Extensions
|
||||
AddMenuItemsId(menuItem.Submenu);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(menuItem.Role) &&
|
||||
string.IsNullOrEmpty(menuItem.Id))
|
||||
if (string.IsNullOrEmpty(menuItem.Id))
|
||||
{
|
||||
menuItem.Id = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user