mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-15 21:26:10 +00:00
ElectronNET.API: Move API code to subfolder
This commit is contained in:
34
src/ElectronNET.API/API/Extensions/EnumExtensions.cs
Normal file
34
src/ElectronNET.API/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();
|
||||
}
|
||||
}
|
||||
}
|
||||
71
src/ElectronNET.API/API/Extensions/MenuItemExtensions.cs
Normal file
71
src/ElectronNET.API/API/Extensions/MenuItemExtensions.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ElectronNET.API.Extensions
|
||||
{
|
||||
internal static class MenuItemExtensions
|
||||
{
|
||||
public static MenuItem[] AddMenuItemsId(this MenuItem[] menuItems)
|
||||
{
|
||||
for (int index = 0; index < menuItems.Length; index++)
|
||||
{
|
||||
var menuItem = menuItems[index];
|
||||
if (menuItem?.Submenu?.Length > 0)
|
||||
{
|
||||
AddMenuItemsId(menuItem.Submenu);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(menuItem.Id) && menuItem.Click != null)
|
||||
{
|
||||
menuItem.Id = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
public static MenuItem GetMenuItem(this List<MenuItem> menuItems, string id)
|
||||
{
|
||||
MenuItem result = new MenuItem();
|
||||
|
||||
foreach (var item in menuItems)
|
||||
{
|
||||
if (item.Id == id)
|
||||
{
|
||||
result = item;
|
||||
}
|
||||
else if (item?.Submenu?.Length > 0)
|
||||
{
|
||||
var menuItem = GetMenuItem(item.Submenu.ToList(), id);
|
||||
if (menuItem.Id == id)
|
||||
{
|
||||
result = menuItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static MenuItem[] AddSubmenuTypes(this MenuItem[] menuItems)
|
||||
{
|
||||
for (int index = 0; index < menuItems.Length; index++)
|
||||
{
|
||||
var menuItem = menuItems[index];
|
||||
if (menuItem?.Submenu?.Length > 0)
|
||||
{
|
||||
if(menuItem.Type == MenuType.normal)
|
||||
{
|
||||
menuItem.Type = MenuType.submenu;
|
||||
}
|
||||
|
||||
AddSubmenuTypes(menuItem.Submenu);
|
||||
}
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ElectronNET.API.Extensions
|
||||
{
|
||||
internal static class ThumbarButtonExtensions
|
||||
{
|
||||
public static ThumbarButton[] AddThumbarButtonsId(this ThumbarButton[] thumbarButtons)
|
||||
{
|
||||
for (int index = 0; index < thumbarButtons.Length; index++)
|
||||
{
|
||||
var thumbarButton = thumbarButtons[index];
|
||||
|
||||
if (string.IsNullOrEmpty(thumbarButton.Id))
|
||||
{
|
||||
thumbarButton.Id = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return thumbarButtons;
|
||||
}
|
||||
|
||||
public static ThumbarButton GetThumbarButton(this List<ThumbarButton> thumbarButtons, string id)
|
||||
{
|
||||
ThumbarButton result = new ThumbarButton("");
|
||||
|
||||
foreach (var item in thumbarButtons)
|
||||
{
|
||||
if (item.Id == id)
|
||||
{
|
||||
result = item;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user