I have few function with the same kind of procedure when only Object does changes. I've tried to write generic function to that group of methods but failed to get ID of T.
Can you help me refactor this ?
List<ObjectOfSomeKind> allObjects = new List<ObjectOfSomeKind>() { new ObjectOfSomeKind{ ID = 1}, new ObjectOfSomeKind { ID = 2 }};
List<ObjectOfSomeKind> objects = new List<ObjectOfSomeKind>();
for (int i = 0; i < ids.Count(); i++)
{
int id = ids.ElementAt(i);
ObjectOfSomeKind object = allObjects .Where(item => item.ID.Equals(id)).SingleOrDefault();
if (object == null)
{
throw new Exception("error");
}
objects.Add(object);
}
new Object { ID = 1}is not valid.. unless you created a class named 'Object'? In which case, don't do that..