如何从Linq方法将参数传递给自定义函数?

时间:2012-12-05 14:38:04

标签: c# linq

如何从Linq ConvertAll方法将filterSettnig参数传递给CalculateEndDateTime方法?

public static List<IAppointment> ConvertToIAppointment(
                                 List<Misa.Runtime.Entities.Agenda> appointments,
                                 AgFilterDisplay filterSettnig)
{
    List<Misa.Agenda.IAppointment> result = null;
    if (appointments != null)
        result = appointments.ConvertAll<IAppointment>(CalculateEndDateTime(/*here i want to pass filterSettnig parameter*/));
    return result;
}

private static IAppointment CalculateEndDateTime(Entities.Agenda agenda, 
                                                 AgFilterDisplay filterSettnig)
{
    IAppointment result = null;

    if (agenda.ClusterID > 0)
    {
        if (agenda.StartDateTime.Date != agenda.EndDateTime.Date)
        {
            agenda.EndDateTime = agenda.StartDateTime.Date.Add(new TimeSpan(23, 59, 59));
        }
    }

    result = (IAppointment)agenda;

    return result;
}

1 个答案:

答案 0 :(得分:2)

使用Select代替,这是LINQ的一部分。 ConvertAllList<T>方法,而不是LINQ方法。

result = appointments.Select(a => CalculateEndDateTime(a, filterSetting))
                     .ToList();