PrimaryKeyException 类 |
命名空间: XPatchLib
[SerializableAttribute] public class PrimaryKeyException : Exception
PrimaryKeyException 类型公开以下成员。
名称 | 说明 | |
---|---|---|
PrimaryKeyException |
初始化 PrimaryKeyException 类的新实例。
| |
PrimaryKeyException(String) |
使用指定的错误信息初始化 PrimaryKeyException 类的新实例。
| |
PrimaryKeyException(String, Exception) |
使用指定错误消息和对作为此异常原因的内部异常的引用来初始化 PrimaryKeyException 类的新实例。
| |
PrimaryKeyException(Type, String) |
使用指定的类型及指定的主键名称创建主键定义异常的实例。
|
名称 | 说明 | |
---|---|---|
ErrorType |
获取异常的类型。
| |
Message |
获取描述当前异常的消息。
(覆写 ExceptionMessage.) | |
PrimaryKeyName |
获取异常的主键名称。
|
名称 | 说明 | |
---|---|---|
GetObjectData |
用关于异常的信息设置 SerializationInfo 。
(覆写 ExceptionGetObjectData(SerializationInfo, StreamingContext).) |
基础类型包含 String、DateTime、Decimal、Guid、 Color、Enum,或者IsPrimitive == true 的类型。
当类型为NullableT时,对 T 进行判断。
当类型定义主键特性时,被标记的主键类型只能是基础类型,否则会抛出异常。
using System; namespace XPatchLib.Example { public class ThrowPrimaryKeyException { public static void Main(string[] args) { try { new Serializer(typeof(ErrorPrimaryKeyDefineClass)); } catch (PrimaryKeyException ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.PrimaryKeyName); Console.WriteLine(ex.ErrorType); } } [XPatchLib.PrimaryKey("Author")] public class ErrorPrimaryKeyDefineClass { public AuthorClass Author { get; set; } } public class AuthorClass { public string FirstName { get; set; } public string SecondName { get; set; } } } }