Statistics
| Branch: | Revision:

root / trunk / hammock / src / net35 / Hammock / Attributes / Validation / RequiredAttribute.cs @ 0eea575a

History | View | Annotate | Download (617 Bytes)

1
using System;
2
using Hammock.Extensions;
3
using Hammock.Validation;
4

    
5
namespace Hammock.Attributes.Validation
6
{
7
#if !SILVERLIGHT
8
    [Serializable]
9
#endif
10
    public class RequiredAttribute : ValidationAttribute
11
    {
12
        public override string TransformValue(System.Reflection.PropertyInfo property, object value)
13
        {
14
            if(value == null)
15
            {
16
                var message = "The property {0} is required, but was null.".FormatWith(property.Name);
17
                throw new ValidationException(message);
18
            }
19
            return base.TransformValue(property, value);
20
        }
21
    }
22
}