This question already has an answer here:
- Get name of property as a string 13 answers
public class WzReferenceCountryValidator : AbstractValidator<IWzReferenceCountryFields>
{
/// <summary>
/// Class constructor.
/// </summary>
public WzReferenceCountryValidator()
{
//Get an instance of the table model so we can get at the data annotations
Reference_CountryTableModel tableModel = new Reference_CountryTableModel();
RuleSet("Fields", () =>
{
RuleFor(aP => aP.SomeField).NotNull()
.NotEmpty()
.Length(tableModel.GetAttributeFrom<MinLengthAttribute>("SomeField").Length, tableModel.GetAttributeFrom<MaxLengthAttribute>("SomeField").Length);
});
}
}
As you can see I am hard coding the "Name" in my call. Is there any way to actually get the name of the field from the instance. So say something lile
tableModel.Name.GetFieldName() ==> "SomeField"
so not the value of tableModel.SomeField but actually its name.
Aucun commentaire:
Enregistrer un commentaire