C# - IDataReader to Object mapping using generics

后端 未结 10 727
情歌与酒
情歌与酒 2020-12-16 19:07

How can I map a DataReader object into a class object by using generics?

For example I need to do the following:

public class Mapper
    {
          


        
10条回答
  •  再見小時候
    2020-12-16 19:50

    Well, i don't know if it fits here, but you could be using the yield keyword

    public static IEnumerable MapObject(IDataReader dr, Func convertFunction)
            {
                while (dr.Read())
                {
                    yield return convertFunction(dr);
                }
            }
    

提交回复
热议问题