2015-06-23 41 views
6

'un Func 'a bir koşulun geçirilmesi Doğrulamalarının özellikleri ve koşulları olan bir tuple listesi oluşturmaya çalışıyorum. Bir Tuple <string, string, Func <bool>>

List<Tuple<string, string, Func<bool>>> properties = new List<Tuple<string, 
                    string, 
                    Func<bool>>> 
{ 
    Tuple.Create(FirstName, "User first name is required", ???), 
}; 
... 

nasıl Func olarak tip (ad == null) ifadesini iletebilirsiniz: Ben bu akılda fikri yoktu? Bunun gibi

cevap

9

(kullanarak lambda expression):

böyle
var properties = new List<Tuple<string, string, Func<bool>>> 
{ 
    Tuple.Create<string, string, Func<bool>>(
       FirstName, 
       "User first name is required", 
       () => FirstName == null), 
}; 
6

şey: lambda ifadeleri çıkarım yazmak için bazı limitatons olduğunu

List<Tuple<string, string, Func<bool>>> properties = new List<Tuple<string, string, Func<bool>>> 
{ 
    Tuple.Create(FirstName, "User first name is required", new Func<bool>(() => FirstName == null)), 
}; 

Not ... Bu nedenle new Func<bool> için Bir delege oluşturma yolu kullanılır.

Alternatifler:

Tuple.Create(FirstName, "User first name is required", (Func<bool>)(() => FirstName == null)), 
Tuple.Create<string, string, Func<bool>>(FirstName, "User first name is required",() => FirstName == null), 
new Tuple<string, string, Func<bool>>(FirstName, "User first name is required",() => FirstName == null), 

Sonunda bir yere Func<bool> repeate gerekiyor.

İlgili konular