要对一个Exception进行继承,怎么写参数为type的方法,有示例代码 多谢
要对一个Exception进行继承,如何写参数为type的方法,有示例代码 谢谢
我要自定义一个错误,然后传一个Type进来,但我上面的定法不行
应该如何写?
谢谢
------解决方案--------------------
你现在什么问题 base.Message 是只读的,不能赋值
------解决方案--------------------
------解决方案--------------------
如果你需要保留基类的消息,你可以再定义一个属性嘛。
public class ExceptionUndefinedEnumConditions : Exception
{
public ExceptionUndefinedEnumConditions(Type type)
{
if (type != null)
{
base.Message = type.ToString();
}
else
{
this.Message = "Type Undefined";
}
}
}
我要自定义一个错误,然后传一个Type进来,但我上面的定法不行
应该如何写?
谢谢
------解决方案--------------------
你现在什么问题 base.Message 是只读的,不能赋值
------解决方案--------------------
public class ExceptionUndefinedEnumConditions : Exception
{
public new string Message
{
get;
set;
}
public ExceptionUndefinedEnumConditions(Type type)
{
if (type != null)
{
this.Message = type.ToString();
}
else
{
this.Message = "Type Undefined";
}
}
}
------解决方案--------------------
如果你需要保留基类的消息,你可以再定义一个属性嘛。