27 lines
749 B
C#
27 lines
749 B
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.WebUtilities;
|
|
|
|
namespace MP.MON.Client
|
|
{
|
|
public static class Utils
|
|
{
|
|
public static T ExtractQueryStringByKey<T>(this NavigationManager navManager, string key)
|
|
{
|
|
Uri uri = navManager.ToAbsoluteUri(navManager.Uri);
|
|
QueryHelpers.ParseQuery(uri.Query).TryGetValue(key, out var value);
|
|
if (typeof(T).Equals(typeof(int)))
|
|
{
|
|
int.TryParse(value, out var result);
|
|
return (T)(object)result;
|
|
}
|
|
|
|
if (typeof(T).Equals(typeof(string)))
|
|
{
|
|
return (T)(object)value.ToString();
|
|
}
|
|
|
|
return default(T);
|
|
}
|
|
}
|
|
}
|