diff --git a/M6502/M6502.Symbols/IdentifiableSection.cs b/M6502/M6502.Symbols/IdentifiableSection.cs index f128b9c..efdf15d 100644 --- a/M6502/M6502.Symbols/IdentifiableSection.cs +++ b/M6502/M6502.Symbols/IdentifiableSection.cs @@ -1,6 +1,7 @@ namespace M6502.Symbols { using System.Collections; + using System.Collections.ObjectModel; using System.Diagnostics; public class IdentifiableSection : Section @@ -14,8 +15,8 @@ private bool MaybeExtractFromParsed(string key, out string? value) { - Debug.Assert(this._parsed is not null); - var found = this._parsed.TryGetValue(key, out var extracted); + Debug.Assert(this.Parsed is not null); + var found = this.Parsed.TryGetValue(key, out var extracted); value = extracted; return found; } @@ -27,10 +28,10 @@ return available; } - protected bool MaybeExtractCompoundInteger(string key, out List value) + protected bool MaybeExtractCompoundInteger(string key, out ReadOnlyCollection value) { var available = this.MaybeExtractFromParsed(key, out var extracted); - value = extracted is null ? [] : ExtractCompoundInteger(extracted); + value = extracted is null ? new ReadOnlyCollection([]) : ExtractCompoundInteger(extracted); return available; } @@ -70,11 +71,11 @@ var referencingContainer = referenceClassAttribute.Referencing; // Get the parent container field - var containerType = this._container.GetType(); + var containerType = this.Container.GetType(); Debug.Assert(referencingContainer is not null); var containerField = containerType.GetField(referencingContainer); Debug.Assert(containerField is not null); - var fieldValue = containerField.GetValue(this._container); + var fieldValue = containerField.GetValue(this.Container); var fieldList = fieldValue as IList; // Now get the referenced object from the parent container field (via ID as an index) @@ -100,7 +101,7 @@ } } - private void ExtractReferencesProperty(List ids, string name, System.Type type) + private void ExtractReferencesProperty(ReadOnlyCollection ids, string name, System.Type type) { // The reference container in the parent class //var referenceSectionProperties = GetSectionProperties(type); diff --git a/M6502/M6502.Symbols/Section.cs b/M6502/M6502.Symbols/Section.cs index 07ebc6b..33eeb9e 100644 --- a/M6502/M6502.Symbols/Section.cs +++ b/M6502/M6502.Symbols/Section.cs @@ -1,6 +1,7 @@ namespace M6502.Symbols { using System; + using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.Numerics; @@ -11,13 +12,15 @@ protected static readonly Dictionary SectionPropertiesCache = []; protected static readonly DateTime UnixEpoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - protected readonly Parser _container; + private readonly Parser _container; // Needed to evaluate references on a second pass - protected readonly Dictionary _references = []; - protected readonly Dictionary> _multipleReferences = []; + private readonly Dictionary _references = []; + private readonly Dictionary> _multipleReferences = []; - protected Dictionary? _parsed; + protected Parser Container => this._container; + + protected Dictionary? Parsed { get; private set; } protected ReflectedSectionProperties SectionProperties => GetSectionProperties(this.GetType()); @@ -48,7 +51,7 @@ public virtual void Parse(Dictionary? entries) { ArgumentNullException.ThrowIfNull(entries); - this._parsed = entries; + this.Parsed = entries; this._container.SectionEntries.Add(this); this.ProcessAttributesOfProperties(); foreach (var entry in entries) @@ -84,7 +87,8 @@ } else if (references) { - this._multipleReferences.Add(key, ExtractCompoundInteger(value)); + var multiple = ExtractCompoundInteger(value); + this._multipleReferences.Add(key, [.. multiple]); } else { @@ -154,7 +158,7 @@ return value.Split('+'); } - protected static List ExtractCompoundInteger(string value) + protected static ReadOnlyCollection ExtractCompoundInteger(string value) { var elements = ExtractCompoundString(value); var returned = new List(elements.Length); @@ -162,7 +166,7 @@ { returned.Add(ExtractInteger(element)); } - return returned; + return returned.AsReadOnly(); } } } \ No newline at end of file