public bool Process(string name, Record[] records) { RecordsRecord rr; if (!this.rdict.TryGetValue(name, out rr)) { rr = new RecordsRecord(); rr.name = name; rr.desc = name; this.rdict.Add(name, rr); } foreach (var r in records) { this.UpdateProgress(); if (!this.CreateSubrecords(rr, r)) { return false; } } // now that we have subrecords, go back through all records foreach (var sr in rr.Items.OfType<Subrecord>()) { // list of all subrecords matching the given name var ss = (from r in records from s in r.SubRecords where s.Name == sr.name select s).ToArray(); this.ProcessSubRecord(sr, ss); } // Post Process IEnumerable<Subrecord> srs = rr.Subrecords; var itr = srs.GetEnumerator(); for (bool atEnd = itr.MoveNext(); !atEnd;) { var sr = itr.Current; if (sr.repeat > 1) { if (sr.size < 0) { sr.size = 0; continue; } int count = sr.repeat; for (int j = 1; j < count; ++j) { atEnd = itr.MoveNext(); if (atEnd) { sr = itr.Current; if (sr.repeat == count) { sr.repeat = sr.optional = 0; } else { // Should be a group?? } } else { sr.repeat = sr.optional = 1; } } } else { atEnd = itr.MoveNext(); } } // sub records have been updated long minSize = records.Min(a => a.Size); long maxSize = records.Max(a => a.Size); if (maxSize == minSize) { // Uniform record size } else { } return true; }