Something went wrong. Try again.
Modular scanner/radio client and multi-broadcast server. uniscan.dexrn.me
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using Microsoft.Extensions.DependencyModel;using UniScan.Network;
namespace UniScan.Client.App.UI.ConnectionMethod;
public static class ConnectionMethodFactoryViewModelSource{ public record ConnectionMethodViewModelFactoryPair(Type Type, ConnectionMethodFactoryViewModelAttribute Attribute);
public static IEnumerable<ConnectionMethodViewModelFactoryPair> Get() { var loaded = AppDomain.CurrentDomain.GetAssemblies() .ToDictionary(a => a.GetName().FullName);
var referenced = DependencyContext.Default?.RuntimeLibraries.SelectMany(l => l.GetDefaultAssemblyNames(DependencyContext .Default)) ?? [];
foreach (AssemblyName assembly in referenced) { if (!loaded.ContainsKey(assembly.FullName)) { try { Assembly.Load(assembly); } catch { // ignored } } } return AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => { try { return assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { return ex.Types.Where(t => t != null).Select(t => t!); } catch { return []; } }) .Where(t => t.IsAssignableTo(typeof(IConnectionMethodFactoryViewModel))) .Select(t => new { Type = t, Attribute = t!.GetCustomAttribute<ConnectionMethodFactoryViewModelAttribute>() }) .Where(x => x.Attribute != null) .Select(t => new ConnectionMethodViewModelFactoryPair(t.Type, t.Attribute!)); }}