Ok The closest I could get is:
class Program
{
static void Main(string[] args)
{
List<long> ids = new List<long> { 1, 2, 3 };
List<Data> dataItems = ids.ConvertToDataItems();
Func<long, Data> selector = (p => new Data { DataId = p });
List<Data> differntDataItems = ids.ConvertToEntities<Data>(selector);
}
}
public class Data
{
public long DataId;
public string Name;
}
public static class ExtensionMethods
{
public static List<Data> ConvertToDataItems(this List<long> dataIds)
{
return dataIds.Select(p => new Data { DataId = p }).ToList();
}
public static List<TProp> ConvertToEntities<TProp>(this List<long> entities, Func<long, TProp> selector)
{
return entities.Select(selector).ToList();
}
}
It works.
I have a feeling that you are a little confused about what you really want as the return type. It would be great to indicate what we want in a method call or smth. For instance:
public static List<TProp> ConvertToEntities<T, TProp>(List<T> entities, Func<T, TProp> selector)
{
return entities.Select(selector).ToList();
}
. , , , , :
this List<long> entities,
.
.