using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using MudBlazor; using System.Reflection; namespace HotelPms.Client.Blazor.Util { public static class MudBlazorExpandEx { internal static ElementReference GetRef(this MudTextField source) { Type type = source.GetType(); BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public; FieldInfo ff = type.GetField("_elementReference", flag); object mudInput = ff.GetValue(source); type = mudInput.GetType(); ff = type.GetField("_elementReference", flag); object _elementReference = ff.GetValue(mudInput); //input or textarea return (ElementReference)_elementReference; } public static ValueTask GetInputValue(this MudTextField source, IJSRuntime JSRuntime) { try { ElementReference e = source.InputReference.ElementReference; return JSRuntime.InvokeAsync("NetCallJs.getInputValue", e); } catch { return ValueTask.FromResult(string.Empty); } } public static ValueTask SetInputValue(this MudTextField source, IJSRuntime JSRuntime, string value) { try { ElementReference e = source.InputReference.ElementReference; return JSRuntime.InvokeVoidAsync("NetCallJs.setInputValue", e, value); } catch { return ValueTask.CompletedTask; } } } }