|
Wersja 752, 0.7 KB
(wprowadzona przez marek, 17 years temu)
|
|
wiersz
|
| Line | |
|---|
| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.ComponentModel.DataAnnotations;
|
|---|
| 5 | using System.Linq;
|
|---|
| 6 | using System.Text;
|
|---|
| 7 | using xVal.ServerSide;
|
|---|
| 8 |
|
|---|
| 9 | namespace 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.