-
-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathCircularReference.cs
More file actions
62 lines (54 loc) · 1.8 KB
/
CircularReference.cs
File metadata and controls
62 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Collections.Generic;
namespace MemoryPack.Tests.Models;
[MemoryPackable(GenerateType.CircularReference)]
public partial class Node
{
[MemoryPackOrder(0)]
public Node? Parent { get; set; }
[MemoryPackOrder(1)]
public Node[]? Children { get; set; }
}
[MemoryPackable(GenerateType.CircularReference)]
public partial class PureNode
{
[MemoryPackOrder(0)]
public int Id { get; set; }
[MemoryPackOrder(1)]
public ulong Id2 { get; set; }
}
[MemoryPackable]
public partial class CircularHolder
{
public List<Node>? List { get; set; }
public List<PureNode>? ListPure { get; set; }
}
// https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/preserve-references?pivots=dotnet-7-0
[MemoryPackable(GenerateType.CircularReference)]
public partial class Employee
{
[MemoryPackOrder(0)]
public string? Name { get; set; }
[MemoryPackOrder(1)]
public Employee? Manager { get; set; }
[MemoryPackOrder(2)]
public List<Employee>? DirectReports { get; set; }
}
[MemoryPackable(GenerateType.CircularReference, SerializeLayout.Sequential)]
public partial class SequentialCircularReference
{
public string? Name { get; set; }
public SequentialCircularReference? Manager { get; set; }
public List<SequentialCircularReference>? DirectReports { get; set; }
}
[MemoryPackable(GenerateType.CircularReference)]
public partial class CircularReferenceWithRequiredProperties
{
[MemoryPackOrder(0)]
public required string FirstName { get; init; }
[MemoryPackOrder(1)]
public required string LastName { get; set; }
[MemoryPackOrder(2)]
public CircularReferenceWithRequiredProperties? Manager { get; init; }
[MemoryPackOrder(3)]
public required List<CircularReferenceWithRequiredProperties> DirectReports { get; set; }
}