IDataErrorInfo
RegisteredUser 实现 IDataErrorInfo 这个接口
问题:不理解这种表达方式,this代表什么, 后边用[]括起来又是什么意思 , 请解释一下
public string this[string propName]
public partial class RegisteredUser:IDataErrorInfo { public string this[string propName] { get { if (propName == "UserName" && string.IsNullOrEmpty(LoginName)) return "用户登录名不能为空"; return string.Empty; } } public string Error { get { return string.Empty; } } }using System;using System.Reflection;namespace System.ComponentModel{ // 摘要: // 提供功能,该功能提供用户界面可以绑定的自定义错误信息。 public interface IDataErrorInfo { // 摘要: // 获取指示对象何处出错的错误信息。 // // 返回结果: // 指示对象何处出错的错误信息。默认值为空字符串 ("")。 string Error { get; } // 摘要: // 获取具有给定名称的属性的错误信息。 // // 参数: // columnName: // 要获取其错误信息的属性的名称。 // // 返回结果: // 该属性的错误信息。默认值为空字符串 ("")。 string this[string columnName] { get; } }}