root/branches/Prowizje/Wierszowki/Wierszowki.Services/DataAnnotationsValidationRunner.cs @ 879

Wersja 752, 0.7 KB (wprowadzona przez marek, 17 years temu)

wiersz

Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.ComponentModel.DataAnnotations;
5using System.Linq;
6using System.Text;
7using xVal.ServerSide;
8
9namespace Wierszowki.Services
10{
11    internal static class DataAnnotationsValidationRunner
12    {
13        public static IEnumerable<ErrorInfo> GetErrors(object instance)
14        {
15            return from prop in TypeDescriptor.GetProperties(instance).Cast<PropertyDescriptor>()
16                   from attribute in prop.Attributes.OfType<ValidationAttribute>()
17                   where !attribute.IsValid(prop.GetValue(instance))
18                   select new ErrorInfo(prop.Name, attribute.FormatErrorMessage(string.Empty), instance);
19        }
20    }
21}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.