-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathWebAssemblyHostBuilderExtensions.cs
More file actions
32 lines (24 loc) · 1.09 KB
/
WebAssemblyHostBuilderExtensions.cs
File metadata and controls
32 lines (24 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Reflection;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Try.UserComponents;
namespace TryMudBlazor.Client.Extensions;
internal static class WebAssemblyHostBuilderExtensions
{
private static readonly MethodInfo ConfigureMethod = ResolveConfigureMethod();
public static void TryInvokeUserStartup(this WebAssemblyHostBuilder builder)
=> ConfigureMethod?.Invoke(null, [builder]);
private static MethodInfo ResolveConfigureMethod()
{
var assembly = typeof(__Main).Assembly;
var startupType =
assembly.GetType("UserStartup", throwOnError: false, ignoreCase: true) ??
assembly.GetType("Try.UserComponents.UserStartup", throwOnError: false, ignoreCase: true);
var method = startupType?.GetMethod("Configure", BindingFlags.Static | BindingFlags.Public);
if (method is null)
return null;
var parameters = method.GetParameters();
if (parameters.Length != 1 || parameters[0].ParameterType != typeof(WebAssemblyHostBuilder))
return null;
return method;
}
}