Skip to content

Commit c344b73

Browse files
committed
Cleanup some code from JsonUtils.cs
1 parent 2ac9ca2 commit c344b73

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

src/WireMock.Net/Util/JsonUtils.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,6 @@ namespace WireMock.Util;
1111

1212
internal static class JsonUtils
1313
{
14-
public static Type CreateTypeFromJObject(JObject instance, string? fullName = null)
15-
{
16-
static Type ConvertType(JToken value, string? propertyName = null)
17-
{
18-
var type = value.Type;
19-
return type switch
20-
{
21-
JTokenType.Array => value.HasValues ? ConvertType(value.First!, propertyName).MakeArrayType() : typeof(object).MakeArrayType(),
22-
JTokenType.Boolean => typeof(bool),
23-
JTokenType.Bytes => typeof(byte[]),
24-
JTokenType.Date => typeof(DateTime),
25-
JTokenType.Guid => typeof(Guid),
26-
JTokenType.Float => typeof(float),
27-
JTokenType.Integer => typeof(long),
28-
JTokenType.Null => typeof(object),
29-
JTokenType.Object => CreateTypeFromJObject((JObject)value, propertyName),
30-
JTokenType.String => typeof(string),
31-
JTokenType.TimeSpan => typeof(TimeSpan),
32-
JTokenType.Uri => typeof(string),
33-
_ => typeof(object)
34-
};
35-
}
36-
37-
var properties = new Dictionary<string, Type>();
38-
foreach (var item in instance.Properties())
39-
{
40-
properties.Add(item.Name, ConvertType(item.Value, item.Name));
41-
}
42-
43-
return TypeBuilderUtils.BuildType(properties, fullName) ?? throw new InvalidOperationException();
44-
}
45-
4614
public static bool TryParseAsJObject(string? strInput, [NotNullWhen(true)] out JObject? value)
4715
{
4816
value = null;
@@ -141,6 +109,9 @@ public static T ParseJTokenToObject<T>(object? value)
141109
};
142110
}
143111

112+
/// <summary>
113+
/// Based on / copied from Handlebars.Net Handlebars.Net.Helpers.Utils.JsonUtils
114+
/// </summary>
144115
public static string GenerateDynamicLinqStatement(JToken jsonObject)
145116
{
146117
var lines = new List<string>();

test/WireMock.Net.Tests/WireMock.Net.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<DefineConstants>NETFRAMEWORK</DefineConstants>
2525
</PropertyGroup>
2626

27+
<ItemGroup>
28+
<Compile Remove="Util\JsonUtilsTests.cs" />
29+
</ItemGroup>
30+
2731
<ItemGroup>
2832
<!-- https://stackoverflow.com/questions/59406201/filenesting-not-working-for-class-or-shared-library-projects -->
2933
<ProjectCapability Include="ConfigurableFileNesting" />

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy