65 lines
1.2 KiB
Plaintext
65 lines
1.2 KiB
Plaintext
@using System.Reflection
|
|
@inherits BaseForm
|
|
@inject HttpClient httpClient
|
|
|
|
|
|
<span>@DisplayName</span>
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
public Type Type { get; set; }
|
|
|
|
[Parameter]
|
|
public long Id { get; set; }
|
|
|
|
private string DisplayName = "";
|
|
|
|
public List<string> PropertyFilters = new List<string> { /* "CreateDate", "UpdateDate" */ };
|
|
|
|
object? model = new object();
|
|
|
|
|
|
|
|
T? GetProperty<T>(PropertyInfo prop)
|
|
{
|
|
return (T)prop.GetValue(model)!;
|
|
}
|
|
|
|
void SetValue<T>(PropertyInfo prop, T value)
|
|
{
|
|
prop.SetValue(model, value);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
model = await httpClient.GetItemAsync(Type, Id);
|
|
|
|
|
|
string? result = null;
|
|
if(model != null)
|
|
{
|
|
try
|
|
{
|
|
result = Type.GetProperties()!.Where(t => t.GetCustomAttribute<DisplayTableTitleAttribute>() != null).SingleOrDefault()!.GetValue(model)!.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if(result != null)
|
|
{
|
|
DisplayName = result;
|
|
}
|
|
else
|
|
{
|
|
DisplayName = Id.ToString();
|
|
}
|
|
|
|
}
|
|
}
|