using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Umbraco.Core.Models;
namespace Umbraco.Core.PropertyEditors
{
///
/// A validator that validates that the value is a valid integer
///
[ValueValidator("Integer")]
internal sealed class IntegerValidator : ManifestValueValidator, IPropertyValidator
{
public override IEnumerable Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor)
{
var result = value.TryConvertTo();
if (result.Success == false)
{
yield return new ValidationResult("The value " + value + " is not a valid integer", new[] {"value"});
}
}
public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor)
{
return Validate(value, "", preValues, editor);
}
}
}