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

Implement more conversions from JsonDynamicValue #15816

Merged
merged 16 commits into from
May 14, 2024
Merged
Changes from 4 commits
Commits
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
@@ -25,20 +25,8 @@ public class JsonDynamicArray : DynamicObject, IEnumerable<JsonNode?>

public object? this[int index]
{
get
{
var value = GetValue(index);
if (value is JsonDynamicValue jsonDynamicValue)
{
return jsonDynamicValue.JsonValue;
}

return value;
}
set
{
SetValue(index, value);
}
get => GetValue(index);
set => SetValue(index, value);
}

public bool Remove(JsonNode? item)
@@ -57,14 +45,7 @@ public void RemoveAt(int index)

public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object? result)
{
var value = GetValue((int)indexes[0]);
if (value is JsonDynamicValue jsonDynamicValue)
{
result = jsonDynamicValue.Value;
return true;
}

result = value;
result = GetValue((int)indexes[0]);
return true;
}

@@ -116,7 +97,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object?[]? args,
return null;
}

public void SetValue(int index, object? value, object? nodeValue = null)
public void SetValue(int index, object? value)
{
if (value is null)
{
@@ -127,8 +108,7 @@ public void SetValue(int index, object? value, object? nodeValue = null)

if (value is not JsonNode)
{
var jsonNode = JNode.FromObject(value);
SetValue(index, jsonNode, value);
value = JNode.FromObject(value);
}

if (value is JsonObject jsonObject)
@@ -148,7 +128,7 @@ public void SetValue(int index, object? value, object? nodeValue = null)
if (value is JsonValue jsonValue)
{
_jsonArray[index] = jsonValue;
_dictionary[index] = new JsonDynamicValue(jsonValue, nodeValue);
_dictionary[index] = new JsonDynamicValue(jsonValue);
return;
}
}
@@ -183,14 +163,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object? result)
return false;
}

var value = GetValue(index);
if (value is JsonDynamicValue jsonDynamicValue)
{
result = jsonDynamicValue.Value;
return true;
}

result = value;
result = GetValue(index);
return true;
}

Original file line number Diff line number Diff line change
@@ -27,20 +27,8 @@ public void Merge(JsonNode? content, JsonMergeSettings? settings = null) =>

public object? this[string key]
{
get
{
var value = GetValue(key);
if (value is JsonDynamicValue jsonDynamicValue)
{
return jsonDynamicValue.JsonValue;
}

return value;
}
set
{
SetValue(key, value);
}
get => GetValue(key);
set => SetValue(key, value);
}

public override bool TryGetMember(GetMemberBinder binder, out object? result)
@@ -57,14 +45,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object? result)
return true;
}

var value = GetValue(binder.Name);
if (value is JsonDynamicValue jsonDynamicValue)
{
result = jsonDynamicValue.Value;
return true;
}

result = value;
result = GetValue(binder.Name);
return true;
}

@@ -127,7 +108,7 @@ public bool Remove(string key)
return null;
}

public void SetValue(string key, object? value, object? nodeValue = null)
public void SetValue(string key, object? value)
{
if (value is null)
{
@@ -138,8 +119,7 @@ public void SetValue(string key, object? value, object? nodeValue = null)

if (value is not JsonNode)
{
var jsonNode = JNode.FromObject(value);
SetValue(key, jsonNode, value);
value = JNode.FromObject(value);
}

if (value is JsonObject jsonObject)
@@ -159,7 +139,7 @@ public void SetValue(string key, object? value, object? nodeValue = null)
if (value is JsonValue jsonValue)
{
_jsonObject[key] = jsonValue;
_dictionary[key] = new JsonDynamicValue(jsonValue, nodeValue);
_dictionary[key] = new JsonDynamicValue(jsonValue);
return;
}
}
Loading