Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IRecord
- {
- int Record_ID { get; set; }
- //Other Properties
- }
- Class TypeA: IRecord
- Class TypeB: IRecord
- DataTable TypeARecords
- DataTable TypeBRecords
- List<IRecord> records; //This may or may not have anything in it, initially.
- private void CreateTypeAObjects()
- {
- DataTable TypeARecords = GetDataMethod();
- foreach (DataRow row in TypeARecords.Rows)
- {
- int recordID = int.Parse(row["Record_ID"].ToString());
- if (records != null && records.Count > 0)
- {
- //If the record is of TypeA and doesn't have an existing object in the collection, create it.
- if ((!records.Where(t => t is TypeA).Any(s => s.Record_ID == recordID)))
- {
- records.Add(new TypeA
- {
- Record_ID = int.Parse(row["Record_ID"].ToString()),
- //Initialize other properties
- });
- }
- }
- else
- {
- //If the list is not instantiated, create it now and add record.
- records = new List<IRecord>();
- records.Add(new TypeA
- {
- Record_ID = int.Parse(row["Record_ID"].ToString()),
- //Initialize Other Properties
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement