代码包含一些冗余数据--如何在不改变其功能的情况下消除冗余并简化代码
此外,我还想知道实现IDataErrorInfo的正确方法
公共字符串错误和公共字符串这个字符串columnName都执行检查空值的工作,我不希望两者都检查空值。
发布于 2017-04-03 09:37:44
一般来说,最好使用验证属性来实现这一点,但是如果谈到具体的示例--您可以删除如下所示的冗余:
public string Error
{
get { return this[null]; }
}
public string this[string columnName]
{
get
{
if (columnName == null || columnName == "UnitCode") {
if (String.IsNullOrEmpty(UnitCode)) {
return "Unit Code cannot be empty";
}
}
if (columnName == null || columnName == "UnitName") {
if (string.IsNullOrEmpty(UnitName)) {
return "Unit Name cannot be Empty";
}
}
return null;
}
}https://stackoverflow.com/questions/43180951
复制相似问题