diff --git a/src/Hl7.Fhir.Base/Introspection/FhirElementAttribute.cs b/src/Hl7.Fhir.Base/Introspection/FhirElementAttribute.cs index 17f9b38c55..65c4cd3167 100644 --- a/src/Hl7.Fhir.Base/Introspection/FhirElementAttribute.cs +++ b/src/Hl7.Fhir.Base/Introspection/FhirElementAttribute.cs @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Reflection; #nullable enable @@ -125,7 +126,18 @@ public FhirElementAttribute(string name, ChoiceType choice, XmlRepresentation re private void validateElement(object value, ValidationContext validationContext, List result) { - DotNetAttributeValidation.TryValidate(value, validationContext.IntoPath(value, validationContext.MemberName ?? Name), result); + var useName = validationContext.MemberName; + if (!string.IsNullOrEmpty(useName)) + { + var pm = ReflectionHelper.FindProperty(validationContext.ObjectType, validationContext.MemberName); + if (pm != null) + { + var at = pm.GetCustomAttribute(); + if (at != null) + useName = at.Name; + } + } + DotNetAttributeValidation.TryValidate(value, validationContext.IntoPath(value, useName ?? Name), result); } } }