File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ Other changes:
88- Added ` [PhpClass()] ` attribute.
99- Added ` StdClass ` and ` EnableTypeLookup ` to deserialization options
1010- Added options for ` PhpSerialization.Serialize() ` .
11- - `ThrowOnCircularReferences` - whether or not to throw on ciruclar references, defaults to false (this might change in the future.)
11+ - `ThrowOnCircularReferences` - whether or not to throw on circular references, defaults to false (this might change in the future.)
1212- Updated and adjusted some of the XML documentation.
1313
1414# 0.4.0
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ This Source Code Form is subject to the terms of the Mozilla Public
44 file, You can obtain one at http://mozilla.org/MPL/2.0/.
55**/
66
7+ using System ;
78using System . Collections . Generic ;
89using Microsoft . VisualStudio . TestTools . UnitTesting ;
910
@@ -31,6 +32,25 @@ public void SerializeCircularObject() {
3132 ) ;
3233 }
3334
35+ [ TestMethod ]
36+ public void ThrowOnCircularReferencesOption ( ) {
37+ var testObject = new CircularClass ( ) {
38+ Foo = "First"
39+ } ;
40+ testObject . Bar = new CircularClass ( ) {
41+ Foo = "Second" ,
42+ Bar = testObject
43+ } ;
44+
45+ var ex = Assert . ThrowsException < ArgumentException > (
46+ ( ) => PhpSerialization . Serialize ( testObject , new PhpSerializiationOptions ( ) { ThrowOnCircularReferences = true } )
47+ ) ;
48+ Assert . AreEqual (
49+ "Input object has a circular reference." ,
50+ ex . Message
51+ ) ;
52+ }
53+
3454 [ TestMethod ]
3555 public void SerializeCircularList ( ) {
3656 List < object > listA = new ( ) { "A" , "B" } ;
Original file line number Diff line number Diff line change @@ -69,8 +69,8 @@ public static T Deserialize<T>(
6969 /// Arrays, lists and dictionaries are serialized into arrays.
7070 /// Objects may also be serialized into arrays, if their respective struct or class does not have the <see cref="PhpClass"/> attribute.
7171 /// </returns>
72- public static string Serialize ( object input ) {
73- return new PhpSerializer ( ) . Serialize ( input ) ;
72+ public static string Serialize ( object input , PhpSerializiationOptions options = null ) {
73+ return new PhpSerializer ( options ) . Serialize ( input ) ;
7474 }
7575 }
7676}
You can’t perform that action at this time.
0 commit comments