weixin_39917090
weixin_39917090
2020-12-27 07:41

FhirBoolean's cause DotNetAttributeValidation.TryValidate to throw an ArgumentException

This is in develop-r4

BooleanPatternAttribute is passed a bool instead of a string, causing the validation to fail outright.

[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public class BooleanPatternAttribute : ValidationAttribute
{
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        if (value == null) return ValidationResult.Success;

        if (value.GetType() != typeof(string)) //<----HERE
            throw new ArgumentException("BooleanPatternAttribute can only be applied to string properties");

        if (FhirBoolean.IsValidValue(value as string))
            return ValidationResult.Success;
        else
            return DotNetAttributeValidation.BuildResult(validationContext, "{0} is not a correctly formatted Boolean", value as string);
    }
}

该提问来源于开源项目:FirelyTeam/firely-net-sdk

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39699163 weixin_39699163 4月前

    Yep. I found this while releasing R4. Thought no one would notice this quickly ;-)

    点赞 评论 复制链接分享
  • weixin_39699163 weixin_39699163 4月前
    • this has changed in the code generation somehow. I found where, and can remove it, but I am interested in whether this appears elsewhere too.....
    点赞 评论 复制链接分享
  • weixin_39699163 weixin_39699163 4月前

    The problem is not the statement above, but the fact that FhirBoolean.Value (in the generated code for FhirBoolean) is now adorned with a BooleanPattern attribute. This should not be the case - and was not in STU3.

    点赞 评论 复制链接分享
  • weixin_39862097 weixin_39862097 4月前

    I did have to do some minor mods to the code generations this time. I'd check the other primitive data types too then.

    点赞 评论 复制链接分享
  • weixin_39699163 weixin_39699163 4月前

    can you indicate when you will fix this? It would be good to produce a bugfix release relatively quickly, this is a blocking issue for everyone using the attribute validators.

    点赞 评论 复制链接分享
  • weixin_39699163 weixin_39699163 4月前
    • I did a quick fix for this in #616, but have no clue why this did not happen in STU3, T4 code seems to be unchanged in this respect.
    点赞 评论 复制链接分享

相关推荐