mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-28 11:47:11 +08:00
25 lines
543 B
C#
25 lines
543 B
C#
#if NET5_0_OR_GREATER
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization.Metadata;
|
|
|
|
namespace Masuit.Tools.Systems;
|
|
|
|
public class SerializeSortByNameResolver : DefaultJsonTypeInfoResolver
|
|
{
|
|
public override JsonTypeInfo GetTypeInfo(Type t, JsonSerializerOptions o)
|
|
{
|
|
var jti = base.GetTypeInfo(t, o);
|
|
int order = 1;
|
|
|
|
foreach (var property in jti.Properties.OrderBy(p => p.Name))
|
|
{
|
|
property.Order = order++;
|
|
}
|
|
|
|
return jti;
|
|
}
|
|
}
|
|
#endif
|