tailieunhanh - Apress Expert C sharp 2005 (Phần 4)

Tham khảo tài liệu 'apress expert c sharp 2005 (phần 4)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 2 27 06 1 23 PM Page 124 124 CHAPTER 3 BUSINESS FRAMEWORK IMPLEMENTATION Inside this method the AddBusinessRules method is called. Before that however the ValidationRules object needs to be given a reference to the business object so it can properly apply the validation rules to the properties. Finally a virtual OnDeserialized method is invoked so the business developer can respond to the deserialization operation if desired. The ValidationRules object maintains a list of currently broken rules. This was used earlier in the implementation of the IsValid property but there s value in exposing the collection itself Browsable false EditorBrowsable public virtual BrokenRulesCollection get return Within ValidationRules this collection is implemented to be read-only. Even though the collection is exposed as a public property it can t be changed by the UI. However the UI can display the list of broken rules to the user if so desired. Windows Forms data binding uses the IDataErrorInfo interface to interrogate a data source for validation errors. This interface allows a data source such as a business object to provide human-readable descriptions of errors at the object and property levels. This information is used by grid controls and the ErrorProvider control to display error icons and tooltip descriptions. The ValidationRules object will provide a list of broken rules for each property on the object making it relatively easy to implement IDataErrorInfo string get if IsValid return .ToString else return string string columnName get string result if IsValid rule .GetFirstBrokenRule columnName if rule null result return result The Error property returns a text .