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:
8
8
- Added ` [PhpClass()] ` attribute.
9
9
- Added ` StdClass ` and ` EnableTypeLookup ` to deserialization options
10
10
- 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.)
12
12
- Updated and adjusted some of the XML documentation.
13
13
14
14
# 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
4
4
file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
5
**/
6
6
7
+ using System ;
7
8
using System . Collections . Generic ;
8
9
using Microsoft . VisualStudio . TestTools . UnitTesting ;
9
10
@@ -31,6 +32,25 @@ public void SerializeCircularObject() {
31
32
) ;
32
33
}
33
34
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
+
34
54
[ TestMethod ]
35
55
public void SerializeCircularList ( ) {
36
56
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>(
69
69
/// Arrays, lists and dictionaries are serialized into arrays.
70
70
/// Objects may also be serialized into arrays, if their respective struct or class does not have the <see cref="PhpClass"/> attribute.
71
71
/// </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 ) ;
74
74
}
75
75
}
76
76
}
You can’t perform that action at this time.
0 commit comments