Skip to content

Commit 6bca3aa

Browse files
committed
Docs: PhpSerializiationOptions
1 parent b8f71ca commit 6bca3aa

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

docs/Options/PhpSerializiationOptions.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,56 @@
1212

1313
# PhpSerializiationOptions
1414

15-
**TODO**
16-
1715
## ThrowOnCircularReferences
1816

19-
**TODO**
17+
**Description:** Whether or not to throw on encountering a circular reference or to terminate it with null.
18+
**Type:** `boolean`
19+
**Default:** `false`
2020

21-
## NumericEnums
21+
### Example 1 - false (default)
22+
23+
When disabled, the offending reference will simply be `null`'d out.
24+
25+
```c#
26+
public class Circular {
27+
public int A { get; set; }
28+
public Circular B { get; set; }
29+
}
30+
31+
var circular = new Circular() { A = 1 };
32+
circular.B = circular;
2233

23-
**TODO**
34+
Console.WriteLine(PhpSerialization.Serialize(circular, new (){ ThrowOnCircularReferences = false}));
35+
// Output: a:2:{s:1:"A";i:1;s:1:"B";N;}
36+
```
37+
38+
### Example 2 - true
39+
```c#
40+
var circular = new Circular() { A = 1 };
41+
circular.B = circular;
42+
43+
Console.WriteLine(PhpSerialization.Serialize(circular, new (){ ThrowOnCircularReferences = true }));
44+
// Throws System.ArgumentException with Message: "Input object has a circular reference."
45+
```
46+
47+
## NumericEnums
2448

25-
## DefaultOptions
49+
**Description:** Whether to serialize enums as numeric values (integers) or using their string representation via `Enum.ToString()`.
50+
**Type:** `boolean`
51+
**Default:** `false`
2652

27-
**TODO**
53+
### Example 1 - false (default)
54+
```c#
55+
public enum MyEnum {
56+
A = 1,
57+
B,
58+
}
59+
Console.WriteLine(PhpSerialization.Serialize(MyEnum.A, new (){ NumericEnums = false }));
60+
// Output: s:1:"A";
61+
```
2862

63+
### Example 2 - true
64+
```c#
65+
Console.WriteLine(PhpSerialization.Serialize(MyEnum.A, new (){ NumericEnums = true }));
66+
// Output: i:1;
67+
```

0 commit comments

Comments
 (0)