Skip to content

Commit 6cb300a

Browse files
committed
version 3.0
1 parent e0d036f commit 6cb300a

File tree

64 files changed

+9765
-5634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9765
-5634
lines changed

Src/STLib.Json.Test/Program.cs

Lines changed: 101 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,119 @@
1-
using System.Data;
1+
using System;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Linq;
4+
using STLib.Json;
25

36
namespace STLib.Json.Test
47
{
5-
internal class Program
8+
public class UserInfo
69
{
7-
[STJson(STJsonSerilizaMode.All)]
8-
public class Student
9-
{
10-
[STJsonProperty("test_name")]
11-
public string Name;
12-
[STJsonProperty]
13-
public int Age;
14-
public Gender Gender;
15-
[STJsonProperty] // optional
16-
public List<string> Hobby;
17-
}
10+
public string Name { get; set; }
11+
public string Github { get; set; }
12+
public string[] Language { get; set; }
13+
public Address Address { get; set; }
14+
}
1815

19-
public enum Gender
20-
{
21-
Male, Female
22-
}
16+
public class Address
17+
{
18+
public string Country { get; set; }
19+
public string Province { get; set; }
20+
public string City { get; set; }
21+
}
2322

24-
static void Main(string[] args) {
25-
DataTable dt = new DataTable();
26-
dt.Columns.Add("name");
27-
dt.Columns.Add("age", typeof(int));
28-
dt.Columns.Add("is_boy", typeof(bool));
29-
for (int i = 0; i < 10; i++) {
30-
DataRow dr = dt.NewRow();
31-
dr["name"] = "test";
32-
dr["age"] = 10;
33-
dr["is_boy"] = i % 2 == 0;
34-
dt.Rows.Add(dr);
35-
}
23+
internal class Program
24+
{
25+
static void Main(string[] args)
26+
{
27+
//var obj_test = STJsonTestObject.CreateTestObject();
28+
var type = typeof(UserInfo);
29+
var obj_test = new UserInfo()
30+
{
31+
Name = "DebugST",
32+
Github = "https://github.com/DebugST",
33+
Language = new string[] { "C#", "JS", "..." },
34+
Address = new Address()
35+
{
36+
Country = "China",
37+
Province = "GuangDong",
38+
City = "ShenZhen"
39+
}
40+
};
41+
string str_json, str_temp;
42+
Console.WriteLine("========================================");
43+
Console.WriteLine(STJson.Serialize(obj_test));
44+
Console.WriteLine("========================================");
3645

37-
var str = STJson.Serialize(dt, 4);
38-
Console.WriteLine(str);
46+
Console.WriteLine("[CHECK_IS_SAME]");
3947

40-
var stu = new Student() {
41-
Name = "Tom",
42-
Age = 20,
43-
Hobby = new List<string>() { "sing", "dance" }
44-
};
45-
object obj = STJsonTestObject.CreateTestObject();
46-
Console.WriteLine(STJson.Serialize(obj, 4));
48+
str_json = JsonConvert.SerializeObject(obj_test);
49+
str_temp = JsonConvert.SerializeObject(JsonConvert.DeserializeObject<UserInfo>(str_json));
50+
Console.WriteLine("Newtonsoft : " + (str_temp == str_json));
4751

48-
str = STJson.Serialize(stu, 4);
49-
Console.WriteLine(str);
50-
stu = STJson.Deserialize<Student>(str);
52+
str_json = STJson.Serialize(obj_test);
53+
str_temp = STJson.Serialize(STJson.Deserialize<UserInfo>(str_json));
54+
Console.WriteLine("STJson : " + (str_temp == str_json));
5155

52-
Console.WriteLine(STJson.Serialize(new System.Drawing.Rectangle(10, 10, 100, 100)));
56+
var sw = new System.Diagnostics.Stopwatch();
5357

54-
Console.WriteLine(STJson.FromObject(stu).Select("..").ToString(4));
58+
int n_counter = 50000;
59+
System.Threading.Thread.Sleep(5000);
60+
Console.WriteLine("========================================");
61+
Console.WriteLine("[Deserialize To Linq] - " + n_counter);
62+
sw.Reset();
63+
sw.Start();
64+
for (int i = 0; i < n_counter; i++) {
65+
JsonConvert.DeserializeObject<JObject>(str_json);
66+
}
67+
sw.Stop();
68+
Console.WriteLine("Newstonoft : " + sw.ElapsedMilliseconds);
5569

56-
//str = STJson.Serialize(obj, 4);
57-
//var sw = new System.Diagnostics.Stopwatch();
58-
//int nCount = 10000;
70+
sw.Reset();
71+
sw.Start();
72+
for (int i = 0; i < n_counter; i++) {
73+
STJson.Deserialize(str_json);
74+
}
75+
sw.Stop();
76+
Console.WriteLine("STJson : " + sw.ElapsedMilliseconds);
77+
// ====================================================================================================
78+
System.Threading.Thread.Sleep(5000);
79+
Console.WriteLine("========================================");
80+
Console.WriteLine("[Deserialize To object] - " + n_counter);
81+
sw.Reset();
82+
sw.Start();
83+
for (int i = 0; i < n_counter; i++) {
84+
JsonConvert.DeserializeObject<UserInfo>(str_json);
85+
}
86+
sw.Stop();
87+
Console.WriteLine("Newstonoft : " + sw.ElapsedMilliseconds);
5988

60-
//while (true) {
61-
// Console.ReadKey();
62-
// Console.WriteLine("===");
89+
sw.Reset();
90+
sw.Start();
91+
for (int i = 0; i < n_counter; i++) {
92+
STJson.Deserialize<UserInfo>(str_json);
93+
}
94+
sw.Stop();
95+
Console.WriteLine("STJson : " + sw.ElapsedMilliseconds);
96+
// ====================================================================================================
97+
System.Threading.Thread.Sleep(5000);
98+
Console.WriteLine("========================================");
99+
Console.WriteLine("[Serialize] - " + n_counter);
100+
sw.Reset();
101+
sw.Start();
102+
for (int i = 0; i < n_counter; i++) {
103+
JsonConvert.SerializeObject(obj_test);
104+
}
105+
sw.Stop();
106+
Console.WriteLine("Newstonoft : " + sw.ElapsedMilliseconds);
63107

64-
// sw.Restart();
65-
// for (int i = 0; i < nCount; i++) {
108+
sw.Reset();
109+
sw.Start();
110+
for (int i = 0; i < n_counter; i++) {
111+
STJson.Serialize(obj_test);
112+
}
113+
sw.Stop();
114+
Console.WriteLine("STJson : " + sw.ElapsedMilliseconds);
66115

67-
// var aaa = STJson.Deserialize<TestObject>(str);
68-
// }
69-
// sw.Stop();
70-
// Console.WriteLine(sw.ElapsedMilliseconds);
71-
//}
116+
Console.ReadKey();
72117
}
73118
}
74119
}

Src/STLib.Json.Test/STJsonTestObject.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
63

74
namespace STLib.Json.Test
85
{
96
public enum TestObjectEnum { Enum1, Enum2, Enum3 }
107

11-
[STJson(STJsonSerilizaMode.All)]
8+
[STJson(STJsonSerializeMode.All)]
129
public class TestObject
1310
{
1411
private string m_private_string = "private_string_obj";

Src/STLib.Json.Test/STLib.Json.Test.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
5+
<TargetFramework>net8.0</TargetFramework>
86
<Title>STJson</Title>
97
<Authors>DebugST</Authors>
108
</PropertyGroup>
119

10+
<ItemGroup>
11+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
12+
</ItemGroup>
13+
1214
<ItemGroup>
1315
<ProjectReference Include="..\STLib.Json\STLib.Json.csproj" />
1416
</ItemGroup>

Src/STLib.Json.sln

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.5.33424.131
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.34930.48
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "STLib.Json", "STLib.Json\STLib.Json.csproj", "{151B52D3-E5D0-4877-8A84-FF7764F270DD}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STLib.Json.Test", "STLib.Json.Test\STLib.Json.Test.csproj", "{E9423C17-AF9B-46F4-BAE6-0D440F9D7095}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "STLib.Json.Test", "STLib.Json.Test\STLib.Json.Test.csproj", "{E9423C17-AF9B-46F4-BAE6-0D440F9D7095}"
99
EndProject
1010
Global
11+
GlobalSection(Performance) = preSolution
12+
HasPerformanceSessions = true
13+
EndGlobalSection
1114
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1215
Debug|Any CPU = Debug|Any CPU
1316
Release|Any CPU = Release|Any CPU
@@ -28,4 +31,10 @@ Global
2831
GlobalSection(ExtensibilityGlobals) = postSolution
2932
SolutionGuid = {C0D3E6E9-5F55-4EC6-8578-F30C609492E6}
3033
EndGlobalSection
34+
GlobalSection(Performance) = preSolution
35+
HasPerformanceSessions = true
36+
EndGlobalSection
37+
GlobalSection(Performance) = preSolution
38+
HasPerformanceSessions = true
39+
EndGlobalSection
3140
EndGlobal

0 commit comments

Comments
 (0)