using System;
using System.Reflection;
using System.Runtime.Serialization;
namespace Masuit.Tools.Mapping.Exceptions
{
///
/// 只读属性的异常
///
[Serializable]
public class ReadOnlyPropertyException : MapperExceptionBase
{
///
/// 构造函数
///
/// 属性
public ReadOnlyPropertyException(PropertyInfo property) : base(ValidateParameter(property))
{
}
///
/// 构造函数
///
public ReadOnlyPropertyException()
{
}
///
/// 构造函数
///
/// 序列化信息
/// 上下文
protected ReadOnlyPropertyException(SerializationInfo serializer, StreamingContext context) : base(serializer, context)
{
}
///
/// 构造函数
///
/// 异常信息
/// 内部异常
public ReadOnlyPropertyException(string exceptionMessage, Exception innerException) : base(exceptionMessage, innerException)
{
}
///
/// 构造函数
///
/// 异常信息
public ReadOnlyPropertyException(string exceptionMessage) : base(exceptionMessage)
{
}
private static string ValidateParameter(PropertyInfo property)
{
return $"目标对象的属性 '{property.Name}' 是只读的";
}
}
}