I have a class called Job and that encapsulates an object of another class called SelectedItem
which has a DateTime
property called ItemDate
;
class Job
{
private SelectedItem m_SelectedItem = null;
public Job() { }
public SelectedItem Item
{
get { return m_SelectedItem; }
set { m_SelectedItem = value; }
}
}
class SelectedItem
{
DateTime m_ItemDate = default(DateTime);
public SelectedItem() { }
public DateTime ItemDate
{
get
{
return (m_ItemDate == default(DateTime))
? DateTime.Now
: m_ItemDate;
}
set { m_ItemDate = value; }
}
}
Then I have a JobManager class that has a List of Job: JobQueue;
class JobManager
{
private ICollection<Job> m_JobQueue = null;
public JobManager()
{
m_JobQueue = new List<Job>();
}
public ReadOnlyCollection<Job> JobQueue
{
get { return m_JobQueue.ToList().AsReadOnly(); }
}
private void CreateJob(SelectedItem item)
{
Job newJob = new Job();
newJob.Item = item;
m_JobQueue.Add(newJob);
}
public IList<Job> GetJobsFromQueue(int quantity, ICollection<Job> ignoreList)
{
return (from job in JobQueue
select job).Skip(ignoreList.Count).Take(quantity).ToList();
}
public void CreateJobQueue(ICollection<SelectedItem> jobData)
{
for (long daysCount = 100; daysCount >= 1; daysCount--)
{
SelectedItem item = GetRandomItem(jobData.ToList()); //This just returns a random item from the specified jobData.
item.ItemDate = DateTime.Today.AddDays((daysCount - 1));
CreateJob(item);
}
}
}
Now the issue is when I call the CreateJobQueue() from the main routine, the ItemDate is correctly inserted as in the future depending upon the daysCount value and populates the JobQueue perfectly.
But when try to retrieve a set of Jobs by calling in GetJobsFromQueue() method, the ItemDate values in the whole of JobQueue is messed up (i.e. different to what has been inserted).
Can anyone have a clue?