I'm having a difficulty returning a generic collection from a Linq Extension. I call the method with a single parameter:
static List<NewPeople> GetPeople()
{
List<People> ppl = Enttity.GetCollection();
var abc = new List<NewPeople>();
ppl.CopyAllTo(abc);
return abc;
//return nppl;
}
Called Method:
public static IList<U> CopyAllTo<T, U>(this IEnumerable<T> source, List<U> destination)
where T : class
where U : class
{
List<U> objectList = new List<U>();
foreach (T t in source)
{
U u = Activator.CreateInstance<U>();
t.CopyTo(u);
objectList.Add(u);
}
return objectList;
}
I can't get the list to return. When I break code on "return ObjectList", there are 3 objects in the list, however, on return to the caller, a null value is returned.
Does anyone know what's wrong with this picture?
destination, and you're not saving the return value fromCopyAllTo.