Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Web.Entity / System / Data / WebControls / EntityDataSourceValidationException.cs
blobf8108d339c133bbb60eaf575e8a6607915ac42af
1 //---------------------------------------------------------------------
2 // <copyright file="EntityDataSourceValidationException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9 using System.Collections.Generic;
10 using System.Diagnostics.CodeAnalysis;
11 using System.Runtime.Serialization;
12 using System.Web.DynamicData;
14 namespace System.Web.UI.WebControls
16 /// <summary>
17 /// Represents errors that occur when validating properties of a dynamic data source.
18 /// </summary>
19 [Serializable]
20 [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification = "SerializeObjectState used instead")]
21 public sealed class EntityDataSourceValidationException : Exception, IDynamicValidatorException
23 /// <summary>
24 /// Exception state used to serialize/deserialize the exception in a safe manner.
25 /// </summary>
26 [NonSerialized]
27 private EntityDataSourceValidationExceptionState _state;
29 /// <summary>
30 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
31 /// </summary>
32 public EntityDataSourceValidationException()
33 : base()
35 InitializeExceptionState(null);
38 /// <summary>
39 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
40 /// </summary>
41 /// <param name="message">Exception message.</param>
42 public EntityDataSourceValidationException(string message)
43 : base(message)
45 InitializeExceptionState(null);
48 /// <summary>
49 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
50 /// </summary>
51 /// <param name="message">Exception message.</param>
52 /// <param name="innerException">Inner exception.</param>
53 public EntityDataSourceValidationException(string message, Exception innerException)
54 : base(message, innerException)
56 InitializeExceptionState(null);
59 /// <summary>
60 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
61 /// </summary>
62 /// <param name="message">Exception message.</param>
63 /// <param name="innerExceptions">Inner exceptions.</param>
64 internal EntityDataSourceValidationException(string message, Dictionary<string, Exception> innerExceptions)
65 : base(message)
67 InitializeExceptionState(innerExceptions);
70 /// <summary>
71 /// Initializes internal exception state.
72 /// </summary>
73 /// <param name="innerExceptions">Inner exceptions.</param>
74 private void InitializeExceptionState(Dictionary<string, Exception> innerExceptions)
76 _state = new EntityDataSourceValidationExceptionState(innerExceptions);
77 SubscribeToSerializeObjectState();
80 /// <summary>
81 /// Returns inner exceptions.
82 /// </summary>
83 IDictionary<string, Exception> IDynamicValidatorException.InnerExceptions
85 get { return _state.InnerExceptions; }
88 /// <summary>
89 /// Subscribes the SerializeObjectState event.
90 /// </summary>
91 private void SubscribeToSerializeObjectState()
93 SerializeObjectState += (exception, eventArgs) => eventArgs.AddSerializedState(_state);
96 /// <summary>
97 /// Holds the exception state that will be serialized when the exception is serialized.
98 /// </summary>
99 [Serializable]
100 private class EntityDataSourceValidationExceptionState : ISafeSerializationData
102 /// <summary>
103 /// Inner exceptions.
104 /// </summary>
105 private readonly Dictionary<string, Exception> _innerExceptions;
107 /// <summary>
108 /// Initializes a new instance of the <see cref="EntityDataSourceValidationExceptionState"/> class.
109 /// </summary>
110 /// <param name="innerExceptions"></param>
111 public EntityDataSourceValidationExceptionState(Dictionary<string, Exception> innerExceptions)
113 _innerExceptions = innerExceptions ?? new Dictionary<string, Exception>();
116 /// <summary>
117 /// Returns inner exceptions.
118 /// </summary>
119 public Dictionary<string, Exception> InnerExceptions
123 return _innerExceptions;
127 /// <summary>
128 /// Completes the deserialization.
129 /// </summary>
130 /// <param name="deserialized">The deserialized object.</param>
131 public void CompleteDeserialization(object deserialized)
133 ((EntityDataSourceValidationException)deserialized)._state = this;