AI OnAI Off
Hi,
I prepared a code snippet:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] class ContentItemCountValidationAttribute : ValidationAttribute { public ContentItemCountValidationAttribute(int numberAllowed) { this.numberAllowed = numberAllowed; } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { //CODE FOR RESOLVING DISPLAY NAME // ------------------------------------ var propertyDefinitionRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>(); var propertyName = validationContext.MemberName; var propertyDefinitionId = ((PageData) validationContext.ObjectInstance).Property[propertyName].PropertyDefinitionID; var propertyDefinition = propertyDefinitionRepository.Load(propertyDefinitionId); propertyDefinition.LocalizationService = LocalizationService.Current; var displayName = propertyDefinition.TranslateDisplayName(); // ------------------------------------ var contentArea = (ContentArea)value; if (contentArea == null || contentArea.Count < numberAllowed) { return new ValidationResult( string.Format("{0} should have at lesat {1} content(s), please provide content(s).", validationContext.DisplayName, numberAllowed), new[] { validationContext.MemberName }); } return ValidationResult.Success; } readonly int numberAllowed; }
Hi guys,
I built a validation based on "ValidationAttribute" as below code:
The problem is "DisplayName" is not localized property name. Is there anyway to get localized version of property name?
Thanks