Skip to content

Commit

Permalink
优化序列法 方法
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhll committed Aug 11, 2023
1 parent 66695dc commit b5f8f85
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="myget.org" value="https://www.myget.org/F/silky-preview/api/v3/index.json" />

</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<LicenseUrl>https://raw.githubusercontent.com/liuhll/silky/main/LICENSE</LicenseUrl>

<Version>3.7.11</Version>
<Version>3.7.12</Version>

<PackageIconUrl>https://raw.githubusercontent.com/liuhll/silky/main/docs/.vuepress/public/assets/logo/logo.png</PackageIconUrl>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public string Serialize(object instance, bool camelCase = true, bool indented =
if (camelCase)
{
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
settings.Converters.Add(new JObjectConverter());
}
else
{
Expand Down
19 changes: 19 additions & 0 deletions framework/src/Silky.Core/Serialization/JObjectConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Dynamic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Silky.Core.Serialization;

public class JObjectConverter : JsonConverter
{
public override bool CanRead => false;

public override bool CanConvert(Type objectType) => objectType == typeof(JObject);

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
=> throw new NotImplementedException();

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
=> JToken.FromObject((value as JObject).ToObject<ExpandoObject>(), serializer).WriteTo(writer);
}
4 changes: 4 additions & 0 deletions framework/test/ITestApplication/Test/ITestAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public interface ITestAppService
[HttpDelete]
Task<string> DeleteAsync(long id);

[HttpGet]
Task<IDictionary<string, string>> TestDict1();


[HttpGet]
Task<PagedList<TestOut>> Search1([FromQuery] string name, [FromQuery] string address,
[FromQuery] IList<long> ids,
Expand Down
11 changes: 10 additions & 1 deletion framework/test/TestApplication/AppService/TestAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task<string> DeleteAsync(long id)
// await _anotherAppService.DeleteOne(input.Name);
// await _anotherAppService.DeleteTwo(input.Address);
// // throw new BusinessException("test exception");
//
//
var entity = await _testRepository.FindOrDefaultAsync(id);
if (entity == null)
{
Expand All @@ -104,6 +104,15 @@ public async Task<string> DeleteAsync(long id)
return "删除数据成功";
}

public async Task<IDictionary<string, string>> TestDict1()
{
return new Dictionary<string, string>()
{
{ "Id", "1" },
{ "Name", "Name" }
};
}

public async Task<PagedList<TestOut>> Search1(string name, string address, IList<long> ids, int pageIndex = 1,
int pageSize = 10)
{
Expand Down

0 comments on commit b5f8f85

Please sign in to comment.