mirror of
https://github.com/milimoe/FunGame-Testing.git
synced 2025-12-05 08:09:04 +00:00
?
This commit is contained in:
parent
bdef920366
commit
dccedd3546
54
Main.cs
54
Main.cs
@ -1,6 +1,52 @@
|
||||
using System.Data;
|
||||
using Milimoe.FunGame.Testing.Solutions;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Common.JsonConverter;
|
||||
|
||||
DataTable dt = DataTableSolution.GetDataTable();
|
||||
DataSet ds = new();
|
||||
DataTable table = new("SampleTable1");
|
||||
table.Columns.Add("Id", typeof(int));
|
||||
table.Columns.Add("Name", typeof(string));
|
||||
table.Columns.Add("Age", typeof(int));
|
||||
table.Rows.Add(1, "John", 30);
|
||||
table.Rows.Add(2, "Jane", 25);
|
||||
table.Rows.Add(3, "Bob", 40);
|
||||
ds.Tables.Add(table);
|
||||
|
||||
Console.WriteLine(dt.Rows[0]["Name"]);
|
||||
table = new("SampleTable2");
|
||||
table.Columns.Add("Id", typeof(int));
|
||||
table.Columns.Add("Name", typeof(string));
|
||||
table.Columns.Add("Age", typeof(int));
|
||||
table.Rows.Add(1, "John", 30);
|
||||
table.Rows.Add(2, "Jane", 25);
|
||||
table.Rows.Add(3, "Bob", 40);
|
||||
ds.Tables.Add(table);
|
||||
|
||||
JsonSerializerOptions options = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||
Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter(), new UserConverter(), new RoomConverter() }
|
||||
};
|
||||
|
||||
Room r = Factory.GetRoom(1294367, "w5rtvh8".ToUpper(), DateTime.Now, Factory.GetUser(), Milimoe.FunGame.Core.Library.Constant.RoomType.Mix, Milimoe.FunGame.Core.Library.Constant.RoomState.Created);
|
||||
User u = Factory.GetUser(1, "LUOLI", "123123", DateTime.Now, DateTime.Now, "LUOLI@66.COM", "QWQAQW");
|
||||
|
||||
Hashtable hashtable = new()
|
||||
{
|
||||
{ "table", table },
|
||||
{ "room", r },
|
||||
{ "user", u }
|
||||
};
|
||||
|
||||
string json = JsonSerializer.Serialize(hashtable, options);
|
||||
|
||||
Hashtable hashtable2 = JsonSerializer.Deserialize<Hashtable>(json, options) ?? new();
|
||||
|
||||
User u2 = NetworkUtility.JsonDeserializeFromHashtable<User>(hashtable2, "user") ?? Factory.GetUser();
|
||||
Room r2 = NetworkUtility.JsonDeserializeFromHashtable<Room>(hashtable2, "room") ?? Factory.GetRoom();
|
||||
|
||||
System.Console.WriteLine(u2.Username + " 进入了 " + r2.Roomid + " 房间");
|
||||
@ -6,22 +6,6 @@ namespace Milimoe.FunGame.Testing.Solutions
|
||||
{
|
||||
public class DataTableSolution
|
||||
{
|
||||
public static DataTable GetDataTable()
|
||||
{
|
||||
DataTable dt = new();
|
||||
dt.Columns.Add(new DataColumn("ID", typeof(int)));
|
||||
dt.Columns.Add(new DataColumn("Name", typeof(string)));
|
||||
DataRow dr = dt.NewRow();
|
||||
dr["ID"] = 1;
|
||||
dr["Name"] = "Mili";
|
||||
dt.Rows.Add(dr);
|
||||
|
||||
JsonObject2 jsonobj = new();
|
||||
|
||||
string json = JsonSerializer.Serialize(dt, jsonobj.Options);
|
||||
DataTable? dt2 = JsonSerializer.Deserialize<DataTable>(json, jsonobj.Options);
|
||||
|
||||
return dt2 ?? new();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user