Forge
csharpdeeb25a2
1#nullable enable
2
3using System.Reflection;
4using System.Text.Json;
5using System.Text.Json.Serialization;
6
7namespace CascadeIDE.Features.WorkspaceNavigation.Application;
8
9/// <summary>Канон слоёв и видов связи correspondence (ADR 0155 §6), <c>wire/correspondence/correspondence-kinds.v1.json</c>.</summary>
10public static class CorrespondenceKindsCatalog
11{
12 private static CorrespondenceKindsDocument? _cached;
13
14 public static CorrespondenceKindsDocument Load()
15 {
16 if (_cached is not null)
17 return _cached;
18
19 var asm = Assembly.GetExecutingAssembly();
20 const string resourceName = "CascadeIDE.wire.correspondence.correspondence-kinds.v1.json";
21 using var stream = asm.GetManifestResourceStream(resourceName)
22 ?? throw new InvalidOperationException($"Missing embedded resource {resourceName}.");
23 _cached = JsonSerializer.Deserialize<CorrespondenceKindsDocument>(stream, JsonOptions)
24 ?? throw new InvalidOperationException("correspondence-kinds.v1.json deserialized to null.");
25 return _cached;
26 }
27
28 private static readonly JsonSerializerOptions JsonOptions = new()
29 {
30 PropertyNameCaseInsensitive = true,
31 };
32
33 public static IReadOnlyList<CorrespondenceLayerDefinition> Layers => Load().Layers;
34
35 public static bool TryGetLayer(string layerId, out CorrespondenceLayerDefinition layer)
36 {
37 layer = Layers.FirstOrDefault(l => string.Equals(l.Id, layerId, StringComparison.OrdinalIgnoreCase))
38 ?? new CorrespondenceLayerDefinition("", "", "", "");
39 return layer.Id.Length > 0;
40 }
41}
42
43public sealed class CorrespondenceKindsDocument
44{
45 [JsonPropertyName("schema_version")]
46 public int SchemaVersion { get; init; }
47
48 [JsonPropertyName("layers")]
49 public List<CorrespondenceLayerDefinition> Layers { get; init; } = [];
50
51 [JsonPropertyName("kinds")]
52 public List<CorrespondenceKindDefinition> Kinds { get; init; } = [];
53}
54
55public sealed record CorrespondenceLayerDefinition(
56 [property: JsonPropertyName("id")] string Id,
57 [property: JsonPropertyName("label")] string Label,
58 [property: JsonPropertyName("title")] string Title,
59 [property: JsonPropertyName("adr")] string Adr);
60
61public sealed class CorrespondenceKindDefinition
62{
63 [JsonPropertyName("id")]
64 public string Id { get; init; } = "";
65
66 [JsonPropertyName("family")]
67 public string Family { get; init; } = "";
68
69 [JsonPropertyName("layers")]
70 public List<string> Layers { get; init; } = [];
71
72 [JsonPropertyName("title")]
73 public string Title { get; init; } = "";
74}
75
View only · write via MCP/CIDE