잊지 않겠습니다.

.NET MVC 및 모든 Component Model에서 Entry의 에러를 표시하는데 사용되는 Interface.
인터페이스는 각 Property에 대한 값을 검사할 수 있도록 this[columnName]에 대한 정의와 객체의 에러 상태를 알아볼 수 있는 Error 라는 string property를 지원한다.

여기에서 각 에러값은 null이 반환될 때, 에러가 없다고 가정이 되며, String.Empty가 반환되는 경우에도 에러라고 인식하게 된다.(ASP.NET MVC)

사용예는 다음과 같다.

01.[Table(Name="Product")]
02.public class Product : IDataErrorInfo
03.{
04.    [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
05.    public int ProductId { get; set; }
06.    [Column]
07.    public string Name { get; set; }
08.    [Column]
09.    public string Description { get; set; }
10.    [Column]
11.    public decimal Price { get; set; }
12.    [Column]
13.    public string Category { get; set; }
14. 
15.    #region IDataErrorInfo Members
16. 
17.    public string Error
18.    {
19.        get { return null; }
20.    }
21. 
22.    public string this[string columnName]
23.    {
24.        get
25.        {
26.            if((columnName == "Name") && string.IsNullOrEmpty(Name))
27.                return "Please enter a product name";
28.            if((columnName == "Description") && string.IsNullOrEmpty(Description))
29.                return "Please enter a description";
30.            if((columnName == "Price") && (Price <= 0))
31.                return "Price must not be negative or zero";
32.            if((columnName == "Category") && string.IsNullOrEmpty(Category))
33.                return "Please specify a category";
34.            return null;
35.        }
36.    }
37. 
38.    #endregion
39.}
Posted by Y2K
,