mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 17:58:47 +02:00
Fix Sonar issues
This commit is contained in:
@@ -72,7 +72,7 @@ namespace WireMock.Matchers
|
||||
switch (input)
|
||||
{
|
||||
case JObject valueAsJObject:
|
||||
value = valueAsJObject; // valueAsJObject.ToObject<object>();
|
||||
value = valueAsJObject;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -32,16 +32,30 @@ namespace WireMock.Util
|
||||
{
|
||||
if (node.Type == JTokenType.Object)
|
||||
{
|
||||
var childLines = new List<string>();
|
||||
ProcessObject(node, propertyName, lines);
|
||||
}
|
||||
else if (node.Type == JTokenType.Array)
|
||||
{
|
||||
ProcessArray(node, propertyName, lines);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProcessItem(node, path, propertyName, lines);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessObject(JToken node, string propertyName, List<string> lines)
|
||||
{
|
||||
var items = new List<string>();
|
||||
var text = new StringBuilder("new (");
|
||||
|
||||
// In case of Object, loop all children. Do a ToArray() to avoid `Collection was modified` exceptions.
|
||||
foreach (JProperty child in node.Children<JProperty>().ToArray())
|
||||
{
|
||||
WalkNode(child.Value, child.Path, child.Name, childLines);
|
||||
WalkNode(child.Value, child.Path, child.Name, items);
|
||||
}
|
||||
|
||||
text.Append(string.Join(", ", childLines));
|
||||
text.Append(string.Join(", ", items));
|
||||
text.Append(")");
|
||||
|
||||
if (!string.IsNullOrEmpty(propertyName))
|
||||
@@ -51,7 +65,8 @@ namespace WireMock.Util
|
||||
|
||||
lines.Add(text.ToString());
|
||||
}
|
||||
else if (node.Type == JTokenType.Array)
|
||||
|
||||
private static void ProcessArray(JToken node, string propertyName, List<string> lines)
|
||||
{
|
||||
var items = new List<string>();
|
||||
var text = new StringBuilder("(new [] { ");
|
||||
@@ -74,7 +89,8 @@ namespace WireMock.Util
|
||||
|
||||
lines.Add(text.ToString());
|
||||
}
|
||||
else
|
||||
|
||||
private static void ProcessItem(JToken node, string path, string propertyName, List<string> lines)
|
||||
{
|
||||
string castText = string.Empty;
|
||||
switch (node.Type)
|
||||
@@ -116,7 +132,8 @@ namespace WireMock.Util
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException($"JTokenType '{node.Type}' cannot be converted to a Dynamic Linq cast operator.");
|
||||
throw new NotSupportedException(
|
||||
$"JTokenType '{node.Type}' cannot be converted to a Dynamic Linq cast operator.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(propertyName))
|
||||
@@ -128,4 +145,3 @@ namespace WireMock.Util
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user