Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds more features back that were lost due to the removal of Newtonsoft #16292

Merged
merged 21 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
354e3bf
Adds missing features back to JsonDynamicValue and other dynamic wrap…
gvkries Jun 11, 2024
caabce8
Merge branch 'main' into gvkries/dyn-16233
gvkries Jun 11, 2024
8a47148
Update src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDyna…
sebastienros Jun 11, 2024
1527ee3
Update src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDyna…
sebastienros Jun 11, 2024
fdb3cf0
Update src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDyna…
sebastienros Jun 11, 2024
0befa3e
Formatting
sebastienros Jun 11, 2024
de86c47
Added JsonConverters for the dynamic wrappers.
gvkries Jun 12, 2024
e7dce82
Merge branch 'gvkries/dyn-16233' of https://github.com/gvkries/Orchar…
gvkries Jun 12, 2024
826aac9
Update src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDyna…
gvkries Jun 12, 2024
24278fa
Merge branch 'main' into gvkries/dyn-16233
gvkries Jun 13, 2024
647aa64
Added a base class for dynamic wrappers and did some code simplificat…
gvkries Jun 13, 2024
165678d
Make classes sealed.
gvkries Jun 13, 2024
4802519
Merge branch 'main' into gvkries/dyn-16233
gvkries Jun 13, 2024
e38f3ba
Merge branch 'main' into gvkries/dyn-16233
MikeAlhayek Jun 13, 2024
7f4ddc3
Update JsonDynamicTests.cs
MikeAlhayek Jun 13, 2024
d114076
Merge branch 'main' into gvkries/dyn-16233
hishamco Jun 15, 2024
6548bba
Merge branch 'main' into gvkries/dyn-16233
gvkries Jun 18, 2024
9dcafc2
Merge branch 'main' into gvkries/dyn-16233
gvkries Jun 26, 2024
4d7b6a6
Update test/OrchardCore.Tests/Data/JsonDynamicTests.cs
gvkries Jun 26, 2024
6afae02
Update test/OrchardCore.Tests/Data/JsonDynamicTests.cs
hishamco Jun 26, 2024
2156020
Update JsonDynamicTests.cs
gvkries Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using System.Linq;
using System.Reflection;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

#nullable enable

namespace System.Text.Json.Dynamic;

[DebuggerDisplay("JsonDynamicArray[{Count}]")]
public class JsonDynamicArray : DynamicObject, IEnumerable<object?>, IEnumerable<JsonNode?>
[JsonConverter(typeof(JsonDynamicJsonConverter<JsonDynamicArray>))]
public sealed class JsonDynamicArray : JsonDynamicBase, IEnumerable<object?>, IEnumerable<JsonNode?>
{
private readonly JsonArray _jsonArray;
private readonly Dictionary<int, object?> _dictionary = [];
Expand All @@ -22,6 +24,8 @@ public class JsonDynamicArray : DynamicObject, IEnumerable<object?>, IEnumerable

public int Count => _jsonArray.Count;

public override JsonNode Node => _jsonArray;

public object? this[int index]
{
get => GetValue(index);
Expand Down Expand Up @@ -140,7 +144,7 @@ public void SetValue(int index, object? value)
}
}

IEnumerator<JsonNode?> IEnumerable<JsonNode?>.GetEnumerator()
IEnumerator<JsonNode?> IEnumerable<JsonNode?>.GetEnumerator()
=> _jsonArray.AsEnumerable().GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Dynamic;
using System.Text.Json.Nodes;

#nullable enable

namespace System.Text.Json.Dynamic;

public abstract class JsonDynamicBase : DynamicObject
{
public abstract JsonNode? Node { get; }
gvkries marked this conversation as resolved.
Show resolved Hide resolved

public T? ToObject<T>() => Node.ToObject<T>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
using System.Dynamic;
using System.Reflection;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.Json.Settings;

#nullable enable

namespace System.Text.Json.Dynamic;

[DebuggerDisplay("JsonDynamicObject[{Count}]")]
public class JsonDynamicObject : DynamicObject
[JsonConverter(typeof(JsonDynamicJsonConverter<JsonDynamicObject>))]
public sealed class JsonDynamicObject : JsonDynamicBase
{
private readonly JsonObject _jsonObject;

private readonly Dictionary<string, object?> _dictionary = [];

public JsonDynamicObject()
Expand All @@ -28,17 +29,19 @@ public JsonDynamicObject(JsonObject jsonObject)

public int Count => _jsonObject.Count;

public void Merge(JsonNode? content, JsonMergeSettings? settings = null)
{
_jsonObject.Merge(content, settings);
}
public override JsonNode Node => _jsonObject;

public object? this[string key]
{
get => GetValue(key);
set => SetValue(key, value);
}

public void Merge(JsonNode? content, JsonMergeSettings? settings = null)
{
_jsonObject.Merge(content, settings);
}
Comment on lines +40 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void Merge(JsonNode? content, JsonMergeSettings? settings = null)
{
_jsonObject.Merge(content, settings);
}
public void Merge(JsonNode? content, JsonMergeSettings? settings = null) => _jsonObject.Merge(content, settings);


public override bool TryGetMember(GetMemberBinder binder, out object? result)
{
if (binder.Name == "{No Member}")
Expand Down
Loading