|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | - |
4 | 1 | namespace MemoryPack.Tests.Models; |
5 | 2 |
|
6 | | -enum TestEnum |
7 | | -{ |
8 | | - A, B, C |
9 | | -} |
10 | | - |
11 | 3 | [MemoryPackable] |
12 | 4 | partial class DefaultValuePlaceholder |
13 | 5 | { |
14 | 6 | public int X { get; set; } |
15 | 7 | } |
16 | 8 |
|
| 9 | +static class StaticMethod |
| 10 | +{ |
| 11 | + public static int GetNumberCalls; |
| 12 | + |
| 13 | + public static int GetNumber() |
| 14 | + { |
| 15 | + GetNumberCalls++; |
| 16 | + return 100; |
| 17 | + } |
| 18 | +} |
| 19 | + |
17 | 20 | [MemoryPackable] |
18 | 21 | partial class FieldDefaultValue |
19 | 22 | { |
20 | 23 | public int X; |
21 | 24 | public int Y = 12345; |
| 25 | + |
| 26 | + [SkipOverwriteByDefault] |
22 | 27 | public float Z = 678.9f; |
23 | | - public string S = "aaaaaaaaa"; |
24 | | - public bool B = true; |
| 28 | + |
| 29 | + [SkipOverwriteByDefault] |
| 30 | + public int FromMethod = StaticMethod.GetNumber(); |
25 | 31 | } |
26 | 32 |
|
27 | 33 | [MemoryPackable] |
28 | 34 | partial class PropertyDefaultValue |
29 | 35 | { |
30 | | - internal enum NestedEnum |
31 | | - { |
32 | | - A, B |
33 | | - } |
34 | | - |
35 | | - public int X { get; set; } |
| 36 | + public int X { get; init; } |
36 | 37 | public int Y { get; set; } = 12345; |
| 38 | + |
| 39 | + [SkipOverwriteByDefault] |
37 | 40 | public float Z { get; set; } = 678.9f; |
38 | | - public string S { get; set; } = "aaaaaaaaa"; |
39 | | - public bool B { get; set; } = true; |
40 | | - public List<string> Alpha { get; set; } = new List<string>(new HashSet<string>()); |
41 | | - public TestEnum E { get; set; } = TestEnum.A; |
42 | | - public NestedEnum E2 { get; set; } = NestedEnum.A; |
43 | | - public (TestEnum, List<string>) Tuple { get; set; } = (TestEnum.A, new List<string>(new HashSet<string>())); |
44 | | - public DateTime Struct { get; set; } = default!; |
45 | | -} |
46 | 41 |
|
47 | | -[MemoryPackable] |
48 | | -partial class CtorParamDefaultValue |
49 | | -{ |
50 | | - public int X; |
51 | | - public int Y; |
52 | | - public float Z; |
53 | | - public string S; |
54 | | - public bool B; |
55 | | - public decimal D; |
56 | | - public DateTime StructValue; |
| 42 | + [SkipOverwriteByDefault] |
| 43 | + public float W { get; init; } = 678.9f; |
57 | 44 |
|
58 | | - [MemoryPackConstructor] |
59 | | - public CtorParamDefaultValue(int x, int y = 12345, float z = 678.9f, string s = "aaaaaa", bool b = true, decimal d = 99M, DateTime structValue = default) |
60 | | - { |
61 | | - X = x; |
62 | | - Y = y; |
63 | | - Z = z; |
64 | | - S = s; |
65 | | - B = b; |
66 | | - D = d; |
67 | | - StructValue = structValue; |
68 | | - } |
| 45 | + [SkipOverwriteByDefault] |
| 46 | + public int FromMethod { get; set; } = StaticMethod.GetNumber(); |
69 | 47 | } |
0 commit comments