From c2e7d3c222fcbfcce9c9a0b44dd7e82742e9cd1f Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 10 Dec 2022 20:24:59 +0800 Subject: Develop secret api. v25 --- .../CrupestApi.Commons/Crud/EntityJsonHelper.cs | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs') diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs new file mode 100644 index 0000000..a1e4583 --- /dev/null +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/EntityJsonHelper.cs @@ -0,0 +1,36 @@ +using System.Text.Json; + +namespace CrupestApi.Commons.Crud; + +public class EntityJsonHelper +{ + private readonly TableInfo _table; + + public EntityJsonHelper(TableInfo table) + { + _table = table; + } + + public virtual JsonDocument ConvertEntityToJson(object? entity) + { + if (entity is null) return JsonSerializer.SerializeToDocument(null); + + var result = new Dictionary(); + + foreach (var column in _table.ColumnInfos) + { + if (column.PropertyInfo is not null) + { + result.Add(column.ColumnName, column.PropertyInfo.GetValue(entity)); + } + } + + return JsonSerializer.SerializeToDocument(result); + } + + public virtual object? ConvertJsonToEntity(JsonDocument? json) + { + // TODO: Implement this. + throw new NotImplementedException(); + } +} -- cgit v1.2.3