ElectronNET.API: Move API code to subfolder

This commit is contained in:
softworkz
2025-10-13 13:20:23 +02:00
parent e4ce61c965
commit feddf5f8f4
145 changed files with 52 additions and 572 deletions

View 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();
}
}
}

View 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;
}
}
}

View File

@@ -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;
}
}
}