mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-01-06 18:31:05 +00:00
Refactor section entry extraction for clarity
This commit is contained in:
parent
ffe559d792
commit
591290c3f5
@ -78,7 +78,7 @@
|
||||
var hasID = this.MaybeExtractIntegerFromParsed(entryName, out var id);
|
||||
if (hasID)
|
||||
{
|
||||
var (name, type, _) = connection;
|
||||
var (name, type) = connection;
|
||||
this.ExtractReferenceProperty(id, name, type);
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,7 @@
|
||||
var hasIDs = this.MaybeExtractCompoundInteger(entryName, out var ids);
|
||||
if (hasIDs)
|
||||
{
|
||||
var (name, type, _) = connection;
|
||||
var (name, type) = connection;
|
||||
this.ExtractReferencesProperty(ids, name, type);
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,10 @@
|
||||
{
|
||||
#region Variables, properties etc.
|
||||
|
||||
// Section -> Unique ID list of dictionary entries
|
||||
|
||||
private Version? _version;
|
||||
private Information? _information;
|
||||
|
||||
// Section -> Unique ID list of dictionary entries
|
||||
public Dictionary<string, List<Dictionary<string, string>>> Parsed { get; } = [];
|
||||
|
||||
public List<Section> SectionEntries { get; } = [];
|
||||
@ -253,22 +252,37 @@
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(key), key, "Debugging section is unavailable");
|
||||
}
|
||||
this.ExtractIdentifiableSection(key, into, parsed);
|
||||
}
|
||||
|
||||
private void ExtractIdentifiableSection<T>(string key, List<T> into, List<Dictionary<string, string>> parsed) where T : IdentifiableSection
|
||||
{
|
||||
into.Capacity = parsed.Count;
|
||||
for (var id = 0; id < parsed.Count; ++id)
|
||||
{
|
||||
Debug.Assert(into.Count == id);
|
||||
var entry = (T?)Activator.CreateInstance(typeof(T), this);
|
||||
Debug.Assert(entry != null);
|
||||
var information = parsed[id];
|
||||
entry.Parse(information);
|
||||
into.Add(entry);
|
||||
this.ExtractIdentifiableEntry(id, parsed, into);
|
||||
}
|
||||
Debug.Assert(into.Count == parsed.Count);
|
||||
|
||||
this.VerifyInformationCount(key, into.Count);
|
||||
}
|
||||
|
||||
private void ExtractIdentifiableEntry<T>(int id, List<Dictionary<string, string>> parsed, List<T> into) where T : IdentifiableSection
|
||||
{
|
||||
Debug.Assert(into.Count == id);
|
||||
var information = parsed[id];
|
||||
var entry = this.ExtractEntry<T>(information);
|
||||
Debug.Assert(into.Capacity > id);
|
||||
into.Add(entry);
|
||||
}
|
||||
|
||||
private T ExtractEntry<T>(Dictionary<string, string> information) where T : Section
|
||||
{
|
||||
var entry = (T?)Activator.CreateInstance(typeof(T), this);
|
||||
Debug.Assert(entry != null);
|
||||
entry.Parse(information);
|
||||
return entry;
|
||||
}
|
||||
|
||||
private void VerifyInformationCount(string key, int actual)
|
||||
{
|
||||
Debug.Assert(this._information != null);
|
||||
@ -310,6 +324,9 @@
|
||||
|
||||
this.ExtractSections();
|
||||
this.ExtractReferences();
|
||||
|
||||
this.Parsed.Clear();
|
||||
|
||||
this.BuildAddressableScopes();
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,9 @@
|
||||
|
||||
internal SectionAttribute? ClassAttribute { get; private set; }
|
||||
|
||||
internal Dictionary<string, Tuple<string, System.Type, SectionPropertyAttribute>> Attributes { get; } = [];
|
||||
internal Dictionary<string, Tuple<string, System.Type>> ReferenceAttributes { get; } = [];
|
||||
|
||||
internal Dictionary<string, Tuple<string, System.Type, SectionReferenceAttribute>> ReferenceAttributes { get; } = [];
|
||||
|
||||
internal Dictionary<string, Tuple<string, System.Type, SectionReferencesAttribute>> ReferencesAttributes { get; } = [];
|
||||
|
||||
//public ReflectedSectionProperties()
|
||||
//{
|
||||
//}
|
||||
internal Dictionary<string, Tuple<string, System.Type>> ReferencesAttributes { get; } = [];
|
||||
|
||||
public void Build(System.Type type)
|
||||
{
|
||||
@ -159,18 +153,14 @@
|
||||
private void ProcessSectionPropertyAttribute(System.Type originalType, string name, SectionPropertyAttribute attribute)
|
||||
{
|
||||
var key = attribute.Key;
|
||||
|
||||
this._entriesToProperties.Add(key, name);
|
||||
|
||||
this.Attributes.Add(key, new Tuple<string, System.Type, SectionPropertyAttribute>(name, originalType, attribute));
|
||||
Debug.Assert(this.Attributes.Count == this.Properties.Count);
|
||||
|
||||
if (attribute is SectionReferenceAttribute referenceAttribute)
|
||||
if (attribute is SectionReferenceAttribute)
|
||||
{
|
||||
this.ReferenceAttributes.Add(key, new Tuple<string, System.Type, SectionReferenceAttribute>(name, originalType, referenceAttribute));
|
||||
this.ReferenceAttributes.Add(key, new Tuple<string, System.Type>(name, originalType));
|
||||
} else if (attribute is SectionReferencesAttribute referencesAttribute)
|
||||
{
|
||||
this.ReferencesAttributes.Add(key, new Tuple<string, System.Type, SectionReferencesAttribute>(name, originalType, referencesAttribute));
|
||||
this.ReferencesAttributes.Add(key, new Tuple<string, System.Type>(name, originalType));
|
||||
}
|
||||
|
||||
var multiples = attribute.Many;
|
||||
|
Loading…
Reference in New Issue
Block a user