Skip to content

Commit

Permalink
#3008 While validating an element, use it's FHIR attribute name not t…
Browse files Browse the repository at this point in the history
…he class property name if it is available.
  • Loading branch information
brianpos committed Jan 14, 2025
1 parent fa4bd61 commit 74055f3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Hl7.Fhir.Base/Introspection/FhirElementAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;

#nullable enable

Expand Down Expand Up @@ -125,7 +126,18 @@ public FhirElementAttribute(string name, ChoiceType choice, XmlRepresentation re

private void validateElement(object value, ValidationContext validationContext, List<ValidationResult> 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<FhirElementAttribute>();
if (at != null)
useName = at.Name;
}
}
DotNetAttributeValidation.TryValidate(value, validationContext.IntoPath(value, useName ?? Name), result);
}
}
}
Expand Down

0 comments on commit 74055f3

Please sign in to comment.