Skip to content

Commit 6e4bafd

Browse files
committed
Update
1 parent 92382bb commit 6e4bafd

11 files changed

+168
-52
lines changed

src/.editorconfig

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,26 @@ dotnet_naming_style.begins_with_i.capitalization = pascal_case
311311

312312
##########################################
313313
# .NET Naming Rules
314-
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/naming-rules
314+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/naming-rules
315315
# 命名规则由 符号规范和命名样式 组成,使用 symbols 和 style 配置,可以复用
316316
##########################################
317317

318+
# all dotnet_naming_symbols propertyValue
319+
# dotnet_naming_symbols.interface.applicable_kinds = namespace, class, struct, interface, enum, property, method, field, event, delegate, parameter, type_parameter, local, local_function
320+
# dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected, local
321+
# dotnet_naming_symbols.interface.required_modifiers = abstract, async, const, readonly, static
322+
323+
# all dotnet_naming_style propertyValue
324+
# dotnet_naming_style.pascal_case.capitalization = pascal_case, camel_case, first_word_upper, all_upper, all_lower
325+
# dotnet_naming_style.pascal_case.required_prefix =
326+
# dotnet_naming_style.pascal_case.required_suffix =
327+
# dotnet_naming_style.pascal_case.word_separator =
328+
329+
# all dotnet_naming_rule propertyValue
330+
# dotnet_naming_rule.private_static_fields_none.symbols = interface
331+
# dotnet_naming_rule.private_static_fields_none.style = pascal_case
332+
# dotnet_naming_rule.private_static_fields_none.severity = none
333+
318334
#### Styles ####
319335

320336
# camel_case_style - Define the camelCase style
@@ -381,7 +397,7 @@ dotnet_naming_style.internal_error_style.required_suffix = ____INTERNAL_ERROR___
381397

382398
# All constant fields must be PascalCase
383399
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1303.md
384-
dotnet_naming_symbols.stylecop_constant_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private
400+
dotnet_naming_symbols.stylecop_constant_fields_group.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected, local
385401
dotnet_naming_symbols.stylecop_constant_fields_group.required_modifiers = const
386402
dotnet_naming_symbols.stylecop_constant_fields_group.applicable_kinds = field
387403
dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.symbols = stylecop_constant_fields_group
@@ -390,7 +406,7 @@ dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.severity
390406

391407
# All static readonly fields must be PascalCase
392408
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1311.md
393-
dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private
409+
dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected, local
394410
# dotnet_naming_symbols.stylecop_static_readonly_fields_group.required_modifiers = static, readonly
395411
dotnet_naming_symbols.stylecop_static_readonly_fields_group.required_modifiers = static
396412
dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_kinds = field
@@ -400,7 +416,7 @@ dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.seve
400416

401417
# No non-private instance fields are allowed
402418
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1401.md
403-
dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected
419+
dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_accessibilities = public, internal, protected, protected_internal, private_protected
404420
dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_kinds = field
405421
dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.symbols = stylecop_fields_must_be_private_group
406422
dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.style = disallowed_style
@@ -444,7 +460,7 @@ dotnet_naming_rule.sanity_check_uncovered_field_case_rule.severity
444460
# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types
445461
# - Constructors, Properties, Events, Methods
446462
# https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-type-members
447-
dotnet_naming_symbols.element_group.applicable_kinds = namespace, class, enum, struct, delegate, event, method, property
463+
dotnet_naming_symbols.element_group.applicable_kinds = namespace, class, struct, enum, property, method, field, event, delegate
448464
dotnet_naming_rule.element_rule.symbols = element_group
449465
dotnet_naming_rule.element_rule.style = pascal_case_style
450466
dotnet_naming_rule.element_rule.severity = warning
@@ -553,8 +569,10 @@ dotnet_diagnostic.IDE0055.severity = suggestion
553569
# IDE0061: 使用本地函数的块主体
554570
dotnet_diagnostic.IDE0061.severity = suggestion
555571

556-
# 使结构字段可写
572+
# 使结构字段可写,不要使用可写字段
557573
dotnet_diagnostic.IDE0064.severity = error
574+
# 结构可以使用字段
575+
dotnet_code_quality.ca1051.exclude_structs = true
558576

559577
# IDE0072: Add missing cases
560578
dotnet_diagnostic.IDE0072.severity = error

src/plugins/MessagePackTest/Benchmarks/ArrayDeserializeBenchmark.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public class ArrayDeserializeBenchmark
2222

2323
#region Constants & Statics
2424

25-
private static readonly MyVector3[] _value = Enumerable.Repeat(
26-
new MyVector3 { X = 10.3f, Y = 40.5f, Z = 13411.3f },
27-
1000)
25+
private static readonly MyVector3[] _value = Enumerable.Repeat(new MyVector3(10.3f, 40.5f, 13411.3f), 1000)
2826
.ToArray();
2927

3028
private static readonly SerializerSession _session;

src/plugins/MessagePackTest/Benchmarks/ArraySerializeBenchmark.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ public class ArraySerializeBenchmark
2424

2525
#region Constants & Statics
2626

27-
private static readonly MyVector3[] _value = Enumerable.Repeat(
28-
new MyVector3 { X = 10.3f, Y = 40.5f, Z = 13411.3f },
29-
1000)
27+
private static readonly MyVector3[] _value = Enumerable.Repeat(new MyVector3(10.3f, 40.5f, 13411.3f), 1000)
3028
.ToArray();
3129

3230
private static readonly ArrayBufferWriter<byte> _arrayBufferWriter;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using MemoryPack;
2+
3+
namespace Orleans.Serialization.MemoryPack;
4+
5+
[MemoryPackable]
6+
public sealed partial record MyMessagePackClass
7+
{
8+
9+
#region Properties
10+
11+
[MemoryPackOrder(0)]
12+
public int IntProperty { get; set; }
13+
14+
[MemoryPackOrder(1)]
15+
public required string StringProperty { get; set; }
16+
17+
[MemoryPackOrder(2)]
18+
public required MyMessagePackSubClass SubClass { get; set; }
19+
20+
[MemoryPackOrder(3)]
21+
public required IMyMessagePackUnion Union { get; set; }
22+
23+
#endregion
24+
25+
}
26+
27+
[MemoryPackable]
28+
public sealed partial record MyMessagePackSubClass
29+
{
30+
31+
#region Properties
32+
33+
[MemoryPackOrder(0)]
34+
public Guid Id { get; set; }
35+
36+
#endregion
37+
38+
}
39+
40+
[MemoryPackable]
41+
[MemoryPackUnion(0, typeof(MyMessagePackUnionVariant1))]
42+
[MemoryPackUnion(1, typeof(MyMessagePackUnionVariant2))]
43+
public partial interface IMyMessagePackUnion
44+
{
45+
}
46+
47+
[MemoryPackable]
48+
public sealed partial record MyMessagePackUnionVariant1 : IMyMessagePackUnion
49+
{
50+
51+
#region Properties
52+
53+
[MemoryPackOrder(0)]
54+
public int IntProperty { get; set; }
55+
56+
#endregion
57+
58+
}
59+
60+
[MemoryPackable]
61+
public sealed partial record MyMessagePackUnionVariant2 : IMyMessagePackUnion
62+
{
63+
64+
#region Properties
65+
66+
[MemoryPackOrder(0)]
67+
public required string StringProperty { get; set; }
68+
69+
#endregion
70+
71+
}

src/plugins/MessagePackTest/Benchmarks/Models/Vector3.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,57 @@ namespace MessagePackTest;
88
[MemoryPackable]
99
[GenerateSerializer]
1010
[Alias("MessagePackTest.MyVector3")]
11-
public partial struct MyVector3
11+
public readonly partial struct MyVector3
1212
{
1313
[Key(0)]
1414
[Id(0)]
1515
[MemoryPackOrder(0)]
16-
public float X;
16+
public readonly float X;
1717

1818
[Key(1)]
1919
[Id(1)]
2020
[MemoryPackOrder(1)]
21-
public float Y;
21+
public readonly float Y;
2222

2323
[Key(2)]
2424
[Id(2)]
2525
[MemoryPackOrder(2)]
26-
public float Z;
26+
public readonly float Z;
27+
28+
public MyVector3(float x, float y, float z)
29+
{
30+
X = x;
31+
Y = y;
32+
Z = z;
33+
}
2734
}
2835

2936
[Immutable]
3037
[MessagePackObject]
3138
[MemoryPackable]
3239
[GenerateSerializer]
3340
[Alias("MessagePackTest.ImmutableVector3")]
34-
public partial struct ImmutableVector3
41+
public readonly partial struct ImmutableVector3
3542
{
3643
[Key(0)]
3744
[Id(0)]
3845
[MemoryPackOrder(0)]
39-
public float X;
46+
public readonly float X;
4047

4148
[Key(1)]
4249
[Id(1)]
4350
[MemoryPackOrder(1)]
44-
public float Y;
51+
public readonly float Y;
4552

4653
[Key(2)]
4754
[Id(2)]
4855
[MemoryPackOrder(2)]
49-
public float Z;
56+
public readonly float Z;
57+
58+
public ImmutableVector3(float x, float y, float z)
59+
{
60+
X = x;
61+
Y = y;
62+
Z = z;
63+
}
5064
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
GenerateType Object Orleans.Serialization.MemoryPack.MyMessagePackClass
2+
---
3+
int IntProperty
4+
string StringProperty
5+
Orleans.Serialization.MemoryPack.MyMessagePackSubClass SubClass
6+
Orleans.Serialization.MemoryPack.IMyMessagePackUnion Union
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GenerateType Object Orleans.Serialization.MemoryPack.MyMessagePackSubClass
2+
---
3+
System.Guid Id
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GenerateType Object Orleans.Serialization.MemoryPack.MyMessagePackUnionVariant1
2+
---
3+
int IntProperty
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GenerateType Object Orleans.Serialization.MemoryPack.MyMessagePackUnionVariant2
2+
---
3+
string StringProperty
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
8-
</PropertyGroup>
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
99

10-
<PropertyGroup>
11-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
12-
<CompilerGeneratedFilesOutputPath>_Generated</CompilerGeneratedFilesOutputPath>
13-
</PropertyGroup>
14-
<ItemGroup>
15-
<Compile Remove="_Generated\**\*.g.cs" />
16-
<None Include="_Generated\**\*.g.cs" />
17-
</ItemGroup>
10+
<PropertyGroup>
11+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
12+
<CompilerGeneratedFilesOutputPath>_Generated</CompilerGeneratedFilesOutputPath>
13+
</PropertyGroup>
14+
<ItemGroup>
15+
<Compile Remove="_Generated\**\*.g.cs" />
16+
<None Include="_Generated\**\*.g.cs" />
17+
</ItemGroup>
1818

19-
<PropertyGroup>
20-
<MemoryPackGenerator_SerializationInfoOutputDirectory>$(MSBuildProjectDirectory)\MemoryPackLogs</MemoryPackGenerator_SerializationInfoOutputDirectory>
21-
</PropertyGroup>
22-
<ItemGroup>
23-
<CompilerVisibleProperty Include="MemoryPackGenerator_SerializationInfoOutputDirectory" />
24-
</ItemGroup>
19+
<PropertyGroup>
20+
<MemoryPackGenerator_SerializationInfoOutputDirectory>$(MSBuildProjectDirectory)\MemoryPackLogs</MemoryPackGenerator_SerializationInfoOutputDirectory>
21+
</PropertyGroup>
22+
<ItemGroup>
23+
<CompilerVisibleProperty Include="MemoryPackGenerator_SerializationInfoOutputDirectory" />
24+
</ItemGroup>
2525

26-
<ItemGroup>
27-
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
28-
<PackageReference Include="MemoryPack" Version="1.21.4" />
29-
<PackageReference Include="MemoryPack.AspNetCoreMvcFormatter" Version="1.21.4" />
30-
<PackageReference Include="MemoryPack.Streaming" Version="1.21.4" />
31-
<PackageReference Include="MessagePack" Version="3.1.4" />
32-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.14.0" />
33-
<PackageReference Include="Microsoft.Orleans.Serialization" Version="9.2.1" />
34-
<PackageReference Include="ResultCore.J" Version="0.2.0" />
35-
</ItemGroup>
26+
<ItemGroup>
27+
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
28+
<PackageReference Include="MemoryPack" Version="1.21.4" />
29+
<PackageReference Include="MemoryPack.AspNetCoreMvcFormatter" Version="1.21.4" />
30+
<PackageReference Include="MemoryPack.Streaming" Version="1.21.4" />
31+
<PackageReference Include="MessagePack" Version="3.1.4" />
32+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.14.0" />
33+
<PackageReference Include="Microsoft.Orleans.Serialization" Version="9.2.1" />
34+
<PackageReference Include="ResultCore.J" Version="0.2.0" />
35+
</ItemGroup>
3636

3737
</Project>

0 commit comments

Comments
 (0)