22using System . Xml ;
33#if SUPPORTS_GRAPHS_SERIALIZATION
44using System . IO ;
5+ using System . Runtime . Serialization ;
56using System . Runtime . Serialization . Formatters . Binary ;
67using System . Xml . XPath ;
78#endif
@@ -45,9 +46,19 @@ public static void SerializeToBinary<TVertex, TEdge>(
4546 /// <typeparam name="TEdge">Edge type.</typeparam>
4647 /// <typeparam name="TGraph">Graph type.</typeparam>
4748 /// <param name="stream">Stream from which deserializing the graph.</param>
49+ /// <param name="binder">
50+ /// <para>
51+ /// <see cref="SerializationBinder"/> used during deserialization.
52+ /// It can be used to check/filter/replace/upgrade types that are loaded.
53+ /// </para>
54+ /// <para>It is also useful in security scenarios.</para>
55+ /// <para>By default no binder is used.</para>
56+ /// </param>
4857 /// <returns>Deserialized graph.</returns>
4958 [ Pure ]
50- public static TGraph DeserializeFromBinary < TVertex , TEdge , TGraph > ( [ NotNull ] this Stream stream )
59+ public static TGraph DeserializeFromBinary < TVertex , TEdge , TGraph > (
60+ [ NotNull ] this Stream stream ,
61+ [ CanBeNull ] SerializationBinder binder = null )
5162 where TGraph : IGraph < TVertex , TEdge >
5263 where TEdge : IEdge < TVertex >
5364 {
@@ -56,7 +67,7 @@ public static TGraph DeserializeFromBinary<TVertex, TEdge, TGraph>([NotNull] thi
5667 if ( ! stream . CanRead )
5768 throw new ArgumentException ( "Must be a readable stream" , nameof ( stream ) ) ;
5869
59- var formatter = new BinaryFormatter ( ) ;
70+ var formatter = new BinaryFormatter { Binder = binder } ;
6071 object result = formatter . Deserialize ( stream ) ;
6172 return ( TGraph ) result ;
6273 }
0 commit comments