summaryrefslogtreecommitdiff
path: root/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs')
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs b/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
new file mode 100644
index 0000000000..896b91fca0
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
@@ -0,0 +1,31 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+
+namespace System.Runtime.Serialization
+{
+ // SafeSerializationEventArgs are provided to the delegates which do safe serialization. Each delegate
+ // serializes its own state into an IDeserializationCallback instance which must, itself, be serializable.
+ // These indivdiual states are then added to the SafeSerializationEventArgs in order to be saved away when
+ // the original ISerializable type is serialized.
+ public sealed class SafeSerializationEventArgs : EventArgs
+ {
+ private readonly List<object> _serializedStates = new List<object>();
+
+ internal SafeSerializationEventArgs() { }
+
+ public void AddSerializedState(ISafeSerializationData serializedState)
+ {
+ if (serializedState == null)
+ throw new ArgumentNullException(nameof(serializedState));
+ if (!serializedState.GetType().IsSerializable)
+ throw new ArgumentException(SR.Format(SR.Serialization_NonSerType, serializedState.GetType(), serializedState.GetType().Assembly.FullName));
+
+ _serializedStates.Add(serializedState);
+ }
+
+ public StreamingContext StreamingContext { get; }
+ }
+}