99 lines
2.1 KiB
Plaintext
99 lines
2.1 KiB
Plaintext
@using System.Reflection
|
|
|
|
|
|
|
|
@inherits BaseForm
|
|
@inject Mf.Razor.Entity.Interfaces.IServiceLocator serviceLocator
|
|
@inject HttpClient httpClient
|
|
|
|
|
|
@foreach(var p in Properties)
|
|
{
|
|
<p>@p.GetDisplayName() : @GetCustomValue(p,model)</p>
|
|
}
|
|
|
|
|
|
@code {
|
|
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
public IJSRuntime Js { get; set; }
|
|
|
|
[Parameter]
|
|
public Type Type { get; set; }
|
|
|
|
[Parameter]
|
|
public long Id { get; set; }
|
|
|
|
|
|
public List<string> PropertyFilters = new List<string> { /* "CreateDate", "UpdateDate" */ };
|
|
|
|
|
|
public List<PropertyInfo> Properties { get; set; } = new();
|
|
|
|
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);
|
|
|
|
Properties = Type.GetProperties().ToList();
|
|
Properties = Properties.Where(p => !PropertyFilters.Any(pp => pp == p.Name)).ToList();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int GetNumber(PropertyInfo property)
|
|
{
|
|
return Properties.IndexOf(property);
|
|
}
|
|
|
|
string? GetCustomValue(PropertyInfo propertyInfo, object ob)
|
|
{
|
|
try
|
|
{
|
|
if (propertyInfo.PropertyType.IsGenericType &&
|
|
propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
|
|
propertyInfo.PropertyType.GetGenericArguments()[0] == typeof(DateTime))
|
|
{
|
|
return (propertyInfo.GetValue(ob) as Nullable<DateTime>)!.Value.ToShamsi();
|
|
}
|
|
|
|
var bb = propertyInfo.PropertyType.Name;
|
|
string? res = propertyInfo.PropertyType.Name switch
|
|
{
|
|
"Guid" => (propertyInfo.GetValue(ob) as Nullable<Guid>).ToString(),
|
|
"DateTime" => (propertyInfo.GetValue(ob) as Nullable<DateTime>)!.Value.ToShamsi(),
|
|
_ => propertyInfo.GetValue(ob)?.ToString()
|
|
};
|
|
return res;
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|