This commit is contained in:
2026-03-13 01:22:28 +01:00
parent 695e4560b5
commit 86641919f8
27 changed files with 755 additions and 344 deletions

View File

@@ -1,7 +1,5 @@
using System.Diagnostics;
using System.Management;
using System.Net.WebSockets;
using System.Text;
using System.Net.WebSockets;
using System.Runtime.CompilerServices;
namespace LeagueAPI;
@@ -9,20 +7,6 @@ public record WebsocketMessageResult(byte[] Message, WebSocketMessageType Messag
public static class Extensions
{
extension(Process process)
{
public string GetCommandLine()
{
if (!OperatingSystem.IsWindows())
{
throw new PlatformNotSupportedException("Only supported on Windows.");
}
using ManagementObjectSearcher searcher = new("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id);
using ManagementObjectCollection objects = searcher.Get();
return objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString() ?? string.Empty;
}
}
extension(string? s)
{
public int ParseInt(int defaultValue = default)
@@ -44,6 +28,40 @@ public static class Extensions
}
}
extension<TSource>(IEnumerable<TSource?> source)
{
/// <summary>
/// Uses <see cref="Enumerable.Aggregate{TSource}(IEnumerable{TSource}, Func{TSource, TSource, TSource})"/>, evaluates immediately.
/// </summary>
public IEnumerable<TSource> WhereNotNull()
{
return source.Aggregate(Enumerable.Empty<TSource>(), Accumulate);
static IEnumerable<TSource> Accumulate(IEnumerable<TSource> accumulator, TSource? next)
{
if (next is not null)
{
return accumulator.Append(next);
}
return accumulator;
}
}
/// <summary>
/// Uses lazy-evaluation
/// </summary>
public IEnumerable<TSource> WhereNotNullLazy()
{
foreach (TSource? element in source)
{
if (element is not null)
{
yield return element;
}
}
}
}
extension<T>(Task<T> task)
{
public T WaitForResult()