8000 make EventHandlerCollection serializable · pythonnet/pythonnet@652f946 · GitHub
[go: up one dir, main page]

Skip to content

Commit 652f946

Browse files
committed
make EventHandlerCollection serializable
1 parent cb4bb9a commit 652f946

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/runtime/EventHandlerCollection.cs

Lines changed: 19 additions & 0 deletions
8C69
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4+
using System.Runtime.Serialization;
5+
using System.Security.Permissions;
46

57
namespace Python.Runtime;
68

9+
[Serializable]
710
internal class EventHandlerCollection: Dictionary<object, List<Handler>>
811
{
912
readonly EventInfo info;
@@ -102,4 +105,20 @@ internal bool RemoveEventHandler(BorrowedReference target, BorrowedReference han
102105
Exceptions.SetError(Exceptions.ValueError, "unknown event handler");
103106
return false;
104107
}
108+
109+
#region Serializable
110+
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
111+
protected EventHandlerCollection(SerializationInfo info, StreamingContext context)
112+
: base(info, context)
113+
{
114+
this.info = (EventInfo)info.GetValue("event", typeof(EventInfo));
115+
}
116+
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
117+
public override void GetObjectData(SerializationInfo info, StreamingContext context)
118+
{
119+
base.GetObjectData(info, context);
120+
121+
info.AddValue("event", this.info);
122+
}
123+
#endregion
105124
}

0 commit comments

Comments
 (0)
0