2012-12-05 74 views
0

如何將filterSettnig參數傳遞給Linq ConvertAll方法中的CalculateEndDateTime方法?如何從Linq方法傳遞參數到自定義函數?

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; 
} 
+0

你使用的是什麼樣的LINQ? LINQ to SharePoint? –

+0

@JohnSaunders它是一個'List',所以它將使它成爲Linq-to-Objects。 – Servy

回答

2

改爲使用Select,它是LINQ的一部分。 ConvertAll是一個List<T>方法,而不是LINQ方法。

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

它是否也支持轉換「結果=(IAppointment)議程」;「 ? –

+0

@NeerajKumarGupta是的,它會返回'IAppointment',它是'CalculateEndDateTime'方法的返回類型。 –

+0

好吧,我正在努力做到這一點..謝謝 –

相關問題