-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (37 loc) · 1.46 KB
/
Copy pathProgram.cs
File metadata and controls
49 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
namespace Specification {
public class Program {
public static void Main(string[] args) {
var mobiles = new List<Mobile>() {
new Mobile(MobileBrand.Apple, MobileType.Smart),
new Mobile(MobileBrand.Samsung, MobileType.Smart),
new Mobile(MobileBrand.Samsung, MobileType.Basic)
};
var smartSpecification = new ExpressionSpecification<Mobile>(mobile => mobile.Type == MobileType.Smart);
var appleSpecification = new ExpressionSpecification<Mobile>(mobile => mobile.Brand == MobileBrand.Apple);
// find all smart mobiles;
var smartMobiles = mobiles.FindAll(mobile => smartSpecification.IsSatisfiedBy(mobile));
// find all apple smart mobiles;
var andSpecification = new AndSpecification<Mobile>(smartSpecification, appleSpecification);
var appleSmartMobiles = mobiles.FindAll(mobile => andSpecification.IsSatisfiedBy(mobile));
Console.WriteLine("Hello World!");
Console.ReadKey();
}
}
class Mobile {
public MobileBrand Brand { get; }
public MobileType Type { get; }
public Mobile(MobileBrand brand, MobileType type) {
Brand = brand;
Type = type;
}
}
enum MobileBrand {
Samsung,
Apple
}
enum MobileType {
Smart, Basic
}
}