Skip to content

Commit 8cbdb91

Browse files
sommmenStringEpsilon
authored andcommitted
Added changelog
Added docs to .sln so i don't have to scoure the repo via file explorer Added Null context aware to library entry point
1 parent 39b560c commit 8cbdb91

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# 1.0
22

33
**Deserialization:**
4+
- Added `string Serialize(object? input, PhpSerializiationOptions? options = null)` to `PhpSerialization` so the target type can be specified at run time.
5+
- `PhpSerialization` (entry point of the library) is now null reference aware, aiding library consumers in caching `NullReferenceException`.
46
- Bugfix: "INF" and "-INF" would not be handled correctly when using explicit typing (`Deserialize<T>`) for some target types.
57
- Bugfix: Properly set classname when deserializing with explicit types that implement IPhpObject.
68
- Performance tweaks:
79
- Minor improvements on memory use during deserialization.
8-
- Improved performance for deserializing Double and Integer values with explicit types.
10+
- Improved performance for deserializing Double and Integer values with explicit types.
911

1012
**General:**
1113
* Bugfix: `PhpSerialization.ClearTypeCache()` was not exposed.

PhpSerializerNET.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PhpSerializerNET", "PhpSeri
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PhpSerializerNET.Test", "PhpSerializerNET.Test\PhpSerializerNET.Test.csproj", "{5C7EBE99-6F08-4721-B737-6D1FE03620E9}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2A8B82C9-337E-4316-B5DA-0E6E4154B186}"
11+
ProjectSection(SolutionItems) = preProject
12+
CHANGELOG.md = CHANGELOG.md
13+
Contributors.md = Contributors.md
14+
LICENSE = LICENSE
15+
README.md = README.md
16+
EndProjectSection
17+
EndProject
1018
Global
1119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1220
Debug|Any CPU = Debug|Any CPU

PhpSerializerNET/PhpSerialization.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ 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+
// Consumers of this library may use https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references
8+
#nullable enable
9+
710
using System;
811
using System.Collections.Generic;
912

@@ -29,7 +32,7 @@ public static class PhpSerialization {
2932
/// <see cref="Dictionary{object,object}"/> for arrays with mixed keys or objects <br/>
3033
/// <see cref="PhpDynamicObject"/> for objects (see options).
3134
/// </returns>
32-
public static object Deserialize(string input, PhpDeserializationOptions options = null) {
35+
public static object? Deserialize(string input, PhpDeserializationOptions? options = null) {
3336
if (string.IsNullOrEmpty(input)) {
3437
throw new ArgumentException("PhpSerialization.Deserialize(): Parameter 'input' must not be null or empty.");
3538
}
@@ -54,7 +57,7 @@ public static object Deserialize(string input, PhpDeserializationOptions options
5457
/// </returns>
5558
public static T Deserialize<T>(
5659
string input,
57-
PhpDeserializationOptions options = null
60+
PhpDeserializationOptions? options = null
5861
) {
5962
if (string.IsNullOrEmpty(input)) {
6063
throw new ArgumentException("PhpSerialization.Deserialize(): Parameter 'input' must not be null or empty.");
@@ -78,10 +81,10 @@ public static T Deserialize<T>(
7881
/// <returns>
7982
/// The deserialized object.
8083
/// </returns>
81-
public static object Deserialize(
84+
public static object? Deserialize(
8285
string input,
8386
Type type,
84-
PhpDeserializationOptions options = null
87+
PhpDeserializationOptions? options = null
8588
) {
8689
if (string.IsNullOrEmpty(input)) {
8790
throw new ArgumentException("PhpSerialization.Deserialize(): Parameter 'input' must not be null or empty.");
@@ -101,8 +104,9 @@ public static object Deserialize(
101104
/// Arrays, lists and dictionaries are serialized into arrays.
102105
/// Objects may also be serialized into arrays, if their respective struct or class does not have the <see cref="PhpClass"/> attribute.
103106
/// </returns>
104-
public static string Serialize(object input, PhpSerializiationOptions options = null) {
105-
return new PhpSerializer(options).Serialize(input);
107+
public static string Serialize(object? input, PhpSerializiationOptions? options = null) {
108+
return new PhpSerializer(options)
109+
.Serialize(input) ?? throw new NullReferenceException($"{nameof(PhpSerializer)}.{nameof(Serialize)} returned null");
106110
}
107111

108112
/// <summary>

0 commit comments

Comments
 (0)