在我们的代码库中找到了这个并花了一些时间来弄清楚(并且必须使用调试器)。这个班级确实只做了一件事但不完全符合预期。
以为我会分享!
编辑摆脱语法错误,抱歉!
public class RecordNotFoundException : ApplicationException
{
readonly string _entityName;
public string EntityName
{
get { return _entityName; }
}
readonly string _details;
public override string Message
{
get
{
return string.Format("Can't find a record for {0}.", _entityName)
+ _details != null ? string.Format(" Details: {0}", _details) : "";
}
}
public RecordNotFoundException(string entityName)
{
_entityName = entityName;
}
public RecordNotFoundException(string entityName, string details)
: this(entityName)
{
_details = details;
}
}
答案 0 :(得分:1)
虽然问题含糊不清,但这是您的问题,请将Message
属性更改为:
public override string Message
{
get
{
return string.Format("Can't find a record for {0}.", _entityName)
+ _details != null ? string.Format(" Details: {0}", _details): String.Empty;
}
}
答案 1 :(得分:0)
属性消息永远不会返回以开头的字符串“无法找到...的记录”