1
//---------------------------------------------------------------------
2 // <copyright file="EntityDataSourceValidationException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
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
17 /// Represents errors that occur when validating properties of a dynamic data source.
20 [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification
= "SerializeObjectState used instead")]
21 public sealed class EntityDataSourceValidationException
: Exception
, IDynamicValidatorException
24 /// Exception state used to serialize/deserialize the exception in a safe manner.
27 private EntityDataSourceValidationExceptionState _state
;
30 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
32 public EntityDataSourceValidationException()
35 InitializeExceptionState(null);
39 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
41 /// <param name="message">Exception message.</param>
42 public EntityDataSourceValidationException(string message
)
45 InitializeExceptionState(null);
49 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
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);
60 /// Initializes a new instance of the <see cref="EntityDataSourceValidationException" /> class.
62 /// <param name="message">Exception message.</param>
63 /// <param name="innerExceptions">Inner exceptions.</param>
64 internal EntityDataSourceValidationException(string message
, Dictionary
<string, Exception
> innerExceptions
)
67 InitializeExceptionState(innerExceptions
);
71 /// Initializes internal exception state.
73 /// <param name="innerExceptions">Inner exceptions.</param>
74 private void InitializeExceptionState(Dictionary
<string, Exception
> innerExceptions
)
76 _state
= new EntityDataSourceValidationExceptionState(innerExceptions
);
77 SubscribeToSerializeObjectState();
81 /// Returns inner exceptions.
83 IDictionary
<string, Exception
> IDynamicValidatorException
.InnerExceptions
85 get { return _state.InnerExceptions; }
89 /// Subscribes the SerializeObjectState event.
91 private void SubscribeToSerializeObjectState()
93 SerializeObjectState
+= (exception
, eventArgs
) => eventArgs
.AddSerializedState(_state
);
97 /// Holds the exception state that will be serialized when the exception is serialized.
100 private class EntityDataSourceValidationExceptionState
: ISafeSerializationData
103 /// Inner exceptions.
105 private readonly Dictionary
<string, Exception
> _innerExceptions
;
108 /// Initializes a new instance of the <see cref="EntityDataSourceValidationExceptionState"/> class.
110 /// <param name="innerExceptions"></param>
111 public EntityDataSourceValidationExceptionState(Dictionary
<string, Exception
> innerExceptions
)
113 _innerExceptions
= innerExceptions
?? new Dictionary
<string, Exception
>();
117 /// Returns inner exceptions.
119 public Dictionary
<string, Exception
> InnerExceptions
123 return _innerExceptions
;
128 /// Completes the deserialization.
130 /// <param name="deserialized">The deserialized object.</param>
131 public void CompleteDeserialization(object deserialized
)
133 ((EntityDataSourceValidationException
)deserialized
)._state
= this;