Skip to content

Commit b20b911

Browse files
committed
[同步]1. 同步到1.5.0-dev1 版本
1 parent 9ec622d commit b20b911

12 files changed

+314
-309
lines changed

GameFrameX.Apps/BsonClassMapHelper.cs

Lines changed: 112 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
1-
using GameFrameX.Utility.Log;
2-
3-
namespace GameFrameX.Apps;
4-
5-
public class DictionaryRepresentationConvention : ConventionBase, IMemberMapConvention
6-
{
7-
private readonly DictionaryRepresentation _dictionaryRepresentation;
8-
9-
public DictionaryRepresentationConvention(DictionaryRepresentation dictionaryRepresentation = DictionaryRepresentation.ArrayOfDocuments)
10-
{
11-
_dictionaryRepresentation = dictionaryRepresentation;
12-
}
13-
14-
public void Apply(BsonMemberMap memberMap)
15-
{
16-
var serializer = memberMap.GetSerializer();
17-
if (serializer is IDictionaryRepresentationConfigurable dictionaryRepresentationConfigurable)
18-
{
19-
var reconfiguredSerializer = dictionaryRepresentationConfigurable.WithDictionaryRepresentation(_dictionaryRepresentation);
20-
memberMap.SetSerializer(reconfiguredSerializer);
21-
}
22-
}
23-
}
24-
25-
public class EmptyContainerSerializeMethodConvention : ConventionBase, IMemberMapConvention
26-
{
27-
public void Apply(BsonMemberMap memberMap)
28-
{
29-
if (memberMap.MemberType.IsGenericType)
30-
{
31-
var genType = memberMap.MemberType.GetGenericTypeDefinition();
32-
if (genType == typeof(List<>))
33-
{
34-
memberMap.SetShouldSerializeMethod(o =>
35-
{
36-
var value = memberMap.Getter(o);
37-
if (value is IList list)
38-
{
39-
return list != null && list.Count > 0;
40-
}
41-
42-
return true;
43-
});
44-
}
45-
46-
else if (genType == typeof(ConcurrentDictionary<,>) || genType == typeof(Dictionary<,>))
47-
{
48-
memberMap.SetShouldSerializeMethod(o =>
49-
{
50-
if (o != null)
51-
{
52-
var value = memberMap.Getter(o);
53-
if (value != null)
54-
{
55-
var countProperty = value.GetType().GetProperty("Count");
56-
if (countProperty != null)
57-
{
58-
var count = (int)countProperty.GetValue(value, null);
59-
return count > 0;
60-
}
61-
}
62-
}
63-
64-
return true;
65-
});
66-
}
67-
}
68-
}
69-
}
70-
71-
public static class BsonClassMapHelper
72-
{
73-
public static void SetConvention()
74-
{
75-
ConventionRegistry.Register(nameof(DictionaryRepresentationConvention),
76-
new ConventionPack { new DictionaryRepresentationConvention(), }, _ => true);
77-
78-
ConventionRegistry.Register(nameof(EmptyContainerSerializeMethodConvention),
79-
new ConventionPack { new EmptyContainerSerializeMethodConvention(), }, _ => true);
80-
}
81-
82-
/// <summary>
83-
/// 提前注册,简化多态类型处理
84-
/// </summary>
85-
/// <param name="assembly"></param>
86-
public static void RegisterAllClass(Assembly assembly)
87-
{
88-
var types = assembly.GetTypes();
89-
foreach (var t in types)
90-
{
91-
try
92-
{
93-
if (!BsonClassMap.IsClassMapRegistered(t))
94-
{
95-
RegisterClass(t);
96-
}
97-
}
98-
catch (Exception e)
99-
{
100-
LogHelper.Error(e);
101-
}
102-
}
103-
}
104-
105-
public static void RegisterClass(Type t)
106-
{
107-
var bsonClassMap = new BsonClassMap(t);
108-
bsonClassMap.AutoMap();
109-
bsonClassMap.SetIgnoreExtraElements(true);
110-
bsonClassMap.SetIgnoreExtraElementsIsInherited(true);
111-
BsonClassMap.RegisterClassMap(bsonClassMap);
112-
}
1+
using GameFrameX.Foundation.Logger;
2+
3+
namespace GameFrameX.Apps;
4+
5+
public class DictionaryRepresentationConvention : ConventionBase, IMemberMapConvention
6+
{
7+
private readonly DictionaryRepresentation _dictionaryRepresentation;
8+
9+
public DictionaryRepresentationConvention(DictionaryRepresentation dictionaryRepresentation = DictionaryRepresentation.ArrayOfDocuments)
10+
{
11+
_dictionaryRepresentation = dictionaryRepresentation;
12+
}
13+
14+
public void Apply(BsonMemberMap memberMap)
15+
{
16+
var serializer = memberMap.GetSerializer();
17+
if (serializer is IDictionaryRepresentationConfigurable dictionaryRepresentationConfigurable)
18+
{
19+
var reconfiguredSerializer = dictionaryRepresentationConfigurable.WithDictionaryRepresentation(_dictionaryRepresentation);
20+
memberMap.SetSerializer(reconfiguredSerializer);
21+
}
22+
}
23+
}
24+
25+
public class EmptyContainerSerializeMethodConvention : ConventionBase, IMemberMapConvention
26+
{
27+
public void Apply(BsonMemberMap memberMap)
28+
{
29+
if (memberMap.MemberType.IsGenericType)
30+
{
31+
var genType = memberMap.MemberType.GetGenericTypeDefinition();
32+
if (genType == typeof(List<>))
33+
{
34+
memberMap.SetShouldSerializeMethod(o =>
35+
{
36+
var value = memberMap.Getter(o);
37+
if (value is IList list)
38+
{
39+
return list != null && list.Count > 0;
40+
}
41+
42+
return true;
43+
});
44+
}
45+
46+
else if (genType == typeof(ConcurrentDictionary<,>) || genType == typeof(Dictionary<,>))
47+
{
48+
memberMap.SetShouldSerializeMethod(o =>
49+
{
50+
if (o != null)
51+
{
52+
var value = memberMap.Getter(o);
53+
if (value != null)
54+
{
55+
var countProperty = value.GetType().GetProperty("Count");
56+
if (countProperty != null)
57+
{
58+
var count = (int)countProperty.GetValue(value, null);
59+
return count > 0;
60+
}
61+
}
62+
}
63+
64+
return true;
65+
});
66+
}
67+
}
68+
}
69+
}
70+
71+
public static class BsonClassMapHelper
72+
{
73+
public static void SetConvention()
74+
{
75+
ConventionRegistry.Register(nameof(DictionaryRepresentationConvention),
76+
new ConventionPack { new DictionaryRepresentationConvention(), }, _ => true);
77+
78+
ConventionRegistry.Register(nameof(EmptyContainerSerializeMethodConvention),
79+
new ConventionPack { new EmptyContainerSerializeMethodConvention(), }, _ => true);
80+
}
81+
82+
/// <summary>
83+
/// 提前注册,简化多态类型处理
84+
/// </summary>
85+
/// <param name="assembly"></param>
86+
public static void RegisterAllClass(Assembly assembly)
87+
{
88+
var types = assembly.GetTypes();
89+
foreach (var t in types)
90+
{
91+
try
92+
{
93+
if (!BsonClassMap.IsClassMapRegistered(t))
94+
{
95+
RegisterClass(t);
96+
}
97+
}
98+
catch (Exception e)
99+
{
100+
LogHelper.Error(e);
101+
}
102+
}
103+
}
104+
105+
public static void RegisterClass(Type t)
106+
{
107+
var bsonClassMap = new BsonClassMap(t);
108+
bsonClassMap.AutoMap();
109+
bsonClassMap.SetIgnoreExtraElements(true);
110+
bsonClassMap.SetIgnoreExtraElementsIsInherited(true);
111+
BsonClassMap.RegisterClassMap(bsonClassMap);
112+
}
113113
}

GameFrameX.Apps/GameFrameX.Apps.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="GameFrameX.Core" Version="1.4.2-dev15" />
21-
<PackageReference Include="GameFrameX.Monitor" Version="1.4.2-dev15" />
2220
<PackageReference Include="Mapster" Version="7.4.0" />
21+
<PackageReference Include="GameFrameX.Core" Version="1.5.0-dev1" />
22+
<PackageReference Include="GameFrameX.Monitor" Version="1.5.0-dev1" />
2323
</ItemGroup>
2424
</Project>

GameFrameX.Config/ConfigComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text.Json;
22
using GameFrameX.Core.Config;
3-
using GameFrameX.Utility.Log;
3+
using GameFrameX.Foundation.Logger;
44

55
namespace GameFrameX.Config;
66

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>disable</Nullable>
7-
<LangVersion>10</LangVersion>
8-
</PropertyGroup>
9-
10-
<ItemGroup>
11-
<None Update="json\*.json">
12-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
13-
</None>
14-
</ItemGroup>
15-
16-
<ItemGroup>
17-
<PackageReference Include="GameFrameX.Core.Config" Version="1.4.2-dev15" />
18-
<PackageReference Include="GameFrameX.Utility" Version="1.4.2-dev15" />
19-
</ItemGroup>
20-
21-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
<LangVersion>10</LangVersion>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Update="json\*.json">
12+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
13+
</None>
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="GameFrameX.Core.Config" Version="1.5.0-dev1" />
18+
<PackageReference Include="GameFrameX.Utility" Version="1.5.0-dev1" />
19+
</ItemGroup>
20+
21+
</Project>

GameFrameX.Hotfix/Common/Events/EventDispatcherExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using GameFrameX.Core.Abstractions.Events;
44
using GameFrameX.Hotfix.Logic.Server.Server;
55
using GameFrameX.Utility.Extensions;
6-
using GameFrameX.Utility.Log;
6+
using GameFrameX.Foundation.Logger;
77
using GameFrameX.Utility.Setting;
88

99
namespace GameFrameX.Hotfix.Common.Events;

0 commit comments

Comments
 (0)