mirror of
https://github.com/rudollee/LearningMVC.git
synced 2025-06-07 16:06:21 +00:00
42 lines
862 B
C#
42 lines
862 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace LanguageFeatures.Models
|
|
{
|
|
public static class MyExtensionMethods
|
|
{
|
|
public static decimal TotalPrices(this IEnumerable<Product> productEnum)
|
|
{
|
|
decimal total = 0;
|
|
foreach (Product prod in productEnum)
|
|
{
|
|
total += prod.Price;
|
|
}
|
|
return total;
|
|
}
|
|
|
|
public static IEnumerable<Product> FilterByCategory(this IEnumerable<Product> productEnum, string categoryParam)
|
|
{
|
|
foreach (Product prod in productEnum)
|
|
{
|
|
if (prod.Category == categoryParam)
|
|
{
|
|
yield return prod;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<Product> Filter(this IEnumerable<Product> productEnum, Func<Product, bool> selectorParm)
|
|
{
|
|
foreach (Product prod in productEnum)
|
|
{
|
|
if (selectorParm(prod))
|
|
{
|
|
yield return prod;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |