Advertisement
Guest User

Untitled

a guest
May 5th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public interface IRecord
  2. {
  3. int Record_ID { get; set; }
  4. //Other Properties
  5. }
  6.  
  7. Class TypeA: IRecord
  8. Class TypeB: IRecord
  9.  
  10. DataTable TypeARecords
  11. DataTable TypeBRecords
  12.  
  13. List<IRecord> records; //This may or may not have anything in it, initially.
  14.  
  15. private void CreateTypeAObjects()
  16. {
  17. DataTable TypeARecords = GetDataMethod();
  18.  
  19.  
  20. foreach (DataRow row in TypeARecords.Rows)
  21. {
  22. int recordID = int.Parse(row["Record_ID"].ToString());
  23.  
  24.  
  25. if (records != null && records.Count > 0)
  26. {
  27. //If the record is of TypeA and doesn't have an existing object in the collection, create it.
  28. if ((!records.Where(t => t is TypeA).Any(s => s.Record_ID == recordID)))
  29. {
  30. records.Add(new TypeA
  31. {
  32. Record_ID = int.Parse(row["Record_ID"].ToString()),
  33. //Initialize other properties
  34. });
  35.  
  36. }
  37. }
  38. else
  39. {
  40. //If the list is not instantiated, create it now and add record.
  41. records = new List<IRecord>();
  42. records.Add(new TypeA
  43. {
  44. Record_ID = int.Parse(row["Record_ID"].ToString()),
  45. //Initialize Other Properties
  46.  
  47. });
  48. }
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement