Func<> & Action<> 差別
發表於 : 週五 7月 08, 2011 2:15 pm
Action 無回傳型態
Func 有回傳型態
Func 有回傳型態
代碼: 選擇全部
MapField<IMobilePhone>(num, m.ContactMechType.Replace(m.VirtualType, string.Empty) , person,
d => d.ContactNumber == num,
(isPrimary, contactMechTypeName, value) =>
person.AddMobilePhone(isPrimary, contactMechTypeName, null, value));
代碼: 選擇全部
private void MapField<T>(string value, string contactMechTypeName, IPerson person, Func<T, bool> pridacate,
Action<bool, string, string> addMechs)
{
if (!string.IsNullOrEmpty(value))
{
IList<T> phones = person.ContactMechs.OfType<T>().ToList();
if (phones.Count() > 0)
{
if (phones.Where(pridacate).Count() == 0)
{
addMechs.Invoke(false, contactMechTypeName, value);
}
}
else
{
addMechs.Invoke(true, contactMechTypeName, value);
}
}
}