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 decimal
///
[ValueValidator("Decimal")]
internal sealed class DecimalValidator : ManifestValueValidator, IPropertyValidator
{
public override IEnumerable Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor)
{
if (value != null && value.ToString() != string.Empty)
{
var result = value.TryConvertTo();
if (result.Success == false)
{
yield return new ValidationResult("The value " + value + " is not a valid decimal", new[] { "value" });
}
}
}
public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor)
{
return Validate(value, "", preValues, editor);
}
}
}