<PackageReference Include="Polly.Core" Version="8.3.0" />

ValidationHelper

static class ValidationHelper
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text; namespace Polly.Utils { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] [ExcludeFromCodeCoverage] internal static class ValidationHelper { [System.Runtime.CompilerServices.NullableContext(2)] [return: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] public static string[] GetMemberName(this ValidationContext validationContext) { string text = validationContext?.MemberName; if (text == null) return null; return new string[1] { text }; } public static string GetDisplayName([System.Runtime.CompilerServices.Nullable(2)] this ValidationContext validationContext) { return validationContext?.DisplayName ?? string.Empty; } [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(TimeSpan))] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "The member of options are preserved and not trimmed. See builder.AddStrategy() extension.")] public static void ValidateObject(ResilienceValidationContext context) { Guard.NotNull(context, "context"); List<ValidationResult> list = new List<ValidationResult>(); if (!Validator.TryValidateObject(context.Instance, new ValidationContext(context.Instance), list, true)) { StringBuilder stringBuilder = new StringBuilder(context.PrimaryMessage); stringBuilder.AppendLine(); stringBuilder.AppendLine("Validation Errors:"); foreach (ValidationResult item in list) { stringBuilder.AppendLine(item.ErrorMessage); } throw new ValidationException(stringBuilder.ToString()); } } } }