AttributeMissException 类 |
命名空间: XPatchLib
[SerializableAttribute] public class AttributeMissException : Exception
AttributeMissException 类型公开以下成员。
名称 | 说明 | |
---|---|---|
AttributeMissException |
初始化 AttributeMissException 类的新实例。
| |
AttributeMissException(String) |
使用指定的错误信息初始化 AttributeMissException 类的新实例。
| |
AttributeMissException(String, Exception) |
使用指定错误消息和对作为此异常原因的内部异常的引用来初始化 AttributeMissException 类的新实例。
| |
AttributeMissException(Type, String) |
使用指定的自定义属性名称初始化 AttributeMissException 类的新实例。
|
名称 | 说明 | |
---|---|---|
AttributeName |
获取当前未找到的自定义特性的名称。
| |
ErrorType |
获取当前未找到特性的类型。
| |
Message |
获取描述当前异常的消息。
(覆写 ExceptionMessage.) |
名称 | 说明 | |
---|---|---|
GetObjectData |
用关于异常的信息设置 SerializationInfo 。
(覆写 ExceptionGetObjectData(SerializationInfo, StreamingContext).) |
当集合元素类型没有定义主键时,在序列化/反序列化 集合对象时会抛出 AttributeMissException 异常。
using System; using System.IO; using System.Text; using System.Xml; namespace XPatchLib.Example { public class ThrowAttributeMissException { public static void Main() { var t = new ThrowAttributeMissException(); t.Divide(); } private void Divide() { var order = CreatePuchaseOrder(); var newOrder = CreatePuchaseOrder(); newOrder.OrderedItems[0].ItemName = "Widget B"; var serializer = new Serializer(typeof(PurchaseOrder)); using (var fs = new MemoryStream()) { using (var writer = new XmlTextWriter(fs, new UTF8Encoding(false))) { try { //由于 OrderedItem 类型没有定义主键,所以在序列化/反序列化 集合对象时会抛出 AttributeMissException 异常。 serializer.Divide(writer, order, newOrder); } catch (AttributeMissException ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.AttributeName); Console.WriteLine(ex.ErrorType); } } } } private PurchaseOrder CreatePuchaseOrder() { var result = new PurchaseOrder(); var i1 = new OrderedItem(); i1.ItemName = "Widget S"; OrderedItem[] items = {i1}; result.OrderedItems = items; return result; } public class OrderedItem { public string ItemName { get; set; } } public class PurchaseOrder { public OrderedItem[] OrderedItems; } } }