From 133fef14d7a77da365c99b4bc91129a59e1299c7 Mon Sep 17 00:00:00 2001
From: Yezi <53083103+yeziuku@users.noreply.github.com>
Date: Mon, 5 Jun 2023 00:31:45 +0800
Subject: [PATCH] Update DataRequest Setter (#28)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Update DataRequest Setter
* Fixed some json bug (#29)
* JsonManager应是internal的
---------
Co-authored-by: milimoe <110188673+milimoe@users.noreply.github.com>
---
Api/Transmittal/DataRequest.cs | 17 +++++++++++++---
Library/Common/Network/SocketObject.cs | 5 +----
Service/JsonManager.cs | 27 +++++++++++++++++++++-----
3 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/Api/Transmittal/DataRequest.cs b/Api/Transmittal/DataRequest.cs
index 0a57d38..c4bbf10 100644
--- a/Api/Transmittal/DataRequest.cs
+++ b/Api/Transmittal/DataRequest.cs
@@ -10,7 +10,17 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
{
public RequestResult Result => Worker.Result;
public string Error => Worker.Error;
- public object? this[string key] => Worker.ResultData[key];
+ public object? this[string key]
+ {
+ get
+ {
+ return Worker.ResultData[key];
+ }
+ set
+ {
+ AddRequestData(key, value);
+ }
+ }
private readonly Request Worker;
@@ -19,9 +29,10 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
Worker = new(Socket, RequestType);
}
- public void AddRequestData(string key, object value)
+ public void AddRequestData(string key, object? value)
{
- Worker.RequestData.Add(key, value);
+ if (Worker.RequestData.ContainsKey(key)) Worker.RequestData[key] = value;
+ else Worker.RequestData.Add(key, value);
}
public RequestResult SendRequest()
diff --git a/Library/Common/Network/SocketObject.cs b/Library/Common/Network/SocketObject.cs
index bcb5fe9..c7fcfc7 100644
--- a/Library/Common/Network/SocketObject.cs
+++ b/Library/Common/Network/SocketObject.cs
@@ -47,10 +47,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
/// 索引超过数组上限
public T? GetParam(int index)
{
- if (index >= Parameters.Length) throw new IndexOutOfArrayLengthException();
- object obj = Parameters[index];
- T? result = JsonManager.GetObject(obj.ToString() ?? "");
- return result;
+ return JsonManager.GetObject(this, index);
}
}
}
diff --git a/Service/JsonManager.cs b/Service/JsonManager.cs
index 619dfb9..225b9e7 100644
--- a/Service/JsonManager.cs
+++ b/Service/JsonManager.cs
@@ -1,10 +1,11 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Milimoe.FunGame.Core.Library.Common.JsonConverter;
+using Milimoe.FunGame.Core.Library.Common.Network;
namespace Milimoe.FunGame.Core.Service
{
- public class JsonManager
+ internal class JsonManager
{
private static bool _IsFirst = true;
private readonly static JsonSerializerOptions _GeneralOptions = new()
@@ -46,7 +47,7 @@ namespace Milimoe.FunGame.Core.Service
///
///
///
- public static string GetString(T obj)
+ internal static string GetString(T obj)
{
return JsonSerializer.Serialize(obj, GeneralOptions);
}
@@ -57,7 +58,7 @@ namespace Milimoe.FunGame.Core.Service
///
///
///
- public static T? GetObject(string json)
+ internal static T? GetObject(string json)
{
return JsonSerializer.Deserialize(json, GeneralOptions);
}
@@ -67,7 +68,7 @@ namespace Milimoe.FunGame.Core.Service
///
///
///
- public static object? GetObject(string json)
+ internal static object? GetObject(string json)
{
return JsonSerializer.Deserialize