public void VisitTagRef(TagRefData field)
{
SeekToOffset(field.Offset);
TagClass tagClass = null;
DatumIndex index;
if (field.WithClass)
{
// Read the datum index based upon the layout
StructureValueCollection values = StructureReader.ReadStructure(_reader, _tagRefLayout);
index = new DatumIndex(values.GetInteger("datum index"));
// Check the class, in case the datum index is null
var magic = values.GetInteger("class magic");
var str = CharConstant.ToString((int)magic);
tagClass = field.Tags.Classes.FirstOrDefault(c => c.TagClassMagic == str);
}
else
{
// Just read the datum index at the current position
index = DatumIndex.ReadFrom(_reader);
}
TagEntry tag = null;
if (index.IsValid && index.Index < field.Tags.Entries.Count)
{
tag = field.Tags.Entries[index.Index];
if (tag == null || tag.RawTag == null || tag.RawTag.Index != index)
tag = null;
}
if (tag != null)
{
field.Class = field.Tags.Classes.FirstOrDefault(c => c.RawClass == tag.RawTag.Class);
field.Value = tag;
}
else
{
field.Class = tagClass;
field.Value = null;
}
}