mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:08:28 +02:00
Cleanup some code from JsonUtils.cs
This commit is contained in:
@@ -11,38 +11,6 @@ namespace WireMock.Util;
|
|||||||
|
|
||||||
internal static class JsonUtils
|
internal static class JsonUtils
|
||||||
{
|
{
|
||||||
public static Type CreateTypeFromJObject(JObject instance, string? fullName = null)
|
|
||||||
{
|
|
||||||
static Type ConvertType(JToken value, string? propertyName = null)
|
|
||||||
{
|
|
||||||
var type = value.Type;
|
|
||||||
return type switch
|
|
||||||
{
|
|
||||||
JTokenType.Array => value.HasValues ? ConvertType(value.First!, propertyName).MakeArrayType() : typeof(object).MakeArrayType(),
|
|
||||||
JTokenType.Boolean => typeof(bool),
|
|
||||||
JTokenType.Bytes => typeof(byte[]),
|
|
||||||
JTokenType.Date => typeof(DateTime),
|
|
||||||
JTokenType.Guid => typeof(Guid),
|
|
||||||
JTokenType.Float => typeof(float),
|
|
||||||
JTokenType.Integer => typeof(long),
|
|
||||||
JTokenType.Null => typeof(object),
|
|
||||||
JTokenType.Object => CreateTypeFromJObject((JObject)value, propertyName),
|
|
||||||
JTokenType.String => typeof(string),
|
|
||||||
JTokenType.TimeSpan => typeof(TimeSpan),
|
|
||||||
JTokenType.Uri => typeof(string),
|
|
||||||
_ => typeof(object)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var properties = new Dictionary<string, Type>();
|
|
||||||
foreach (var item in instance.Properties())
|
|
||||||
{
|
|
||||||
properties.Add(item.Name, ConvertType(item.Value, item.Name));
|
|
||||||
}
|
|
||||||
|
|
||||||
return TypeBuilderUtils.BuildType(properties, fullName) ?? throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool TryParseAsJObject(string? strInput, [NotNullWhen(true)] out JObject? value)
|
public static bool TryParseAsJObject(string? strInput, [NotNullWhen(true)] out JObject? value)
|
||||||
{
|
{
|
||||||
value = null;
|
value = null;
|
||||||
@@ -141,6 +109,9 @@ internal static class JsonUtils
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Based on / copied from Handlebars.Net Handlebars.Net.Helpers.Utils.JsonUtils
|
||||||
|
/// </summary>
|
||||||
public static string GenerateDynamicLinqStatement(JToken jsonObject)
|
public static string GenerateDynamicLinqStatement(JToken jsonObject)
|
||||||
{
|
{
|
||||||
var lines = new List<string>();
|
var lines = new List<string>();
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
<DefineConstants>NETFRAMEWORK</DefineConstants>
|
<DefineConstants>NETFRAMEWORK</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="Util\JsonUtilsTests.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- https://stackoverflow.com/questions/59406201/filenesting-not-working-for-class-or-shared-library-projects -->
|
<!-- https://stackoverflow.com/questions/59406201/filenesting-not-working-for-class-or-shared-library-projects -->
|
||||||
<ProjectCapability Include="ConfigurableFileNesting" />
|
<ProjectCapability Include="ConfigurableFileNesting" />
|
||||||
|
|||||||
Reference in New Issue
Block a user