I have created a Blazor Component to handle editing a database record which is defined by a class.
I would like this component to be reused to edit other records – that have the same structure, but different field names.
For example, here is one of my class definitions:
public class AccountTypeCode
{
public int AccountTypeId { get; set; }
[Required]
public string AccountType { get; set; } = string.Empty;
[Required]
public string? AccountTypeDescription { get; set; } = string.Empty;
public string AdditionalInformation { get; set; } = string.Empty;
public int DisplayOrder { get; set; } = 0;
public DateOnly? DateTerminated { get; set; }
}
Another class might refer to CustomerTypeId, CustomerType, CustomerTypeDescription, etc.
In my component’s @code section I currently have code like:
if (recordEdit is not null && !string.IsNullOrEmpty(recordEdit.AccountType))
{
onSaveButton(recordEdit.AccountType);
}
Where recordEdit is of type AccountTypeCode.
What I want to do is replace, for example, recordEdit.AccountType with a generic recordEdit.RecordType
By doing this I can reuse my component many times without having to write a new component for each table that I want to edit.