本文整理汇总了C#中ExpressionSpecification.IsSatisfiedBy方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSpecification.IsSatisfiedBy方法的具体用法?C# ExpressionSpecification.IsSatisfiedBy怎么用?C# ExpressionSpecification.IsSatisfiedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSpecification
的用法示例。
在下文中一共展示了ExpressionSpecification.IsSatisfiedBy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var someBookstore = new Bookstore("Shakespeare and Company");
var witchesAbroad = new Book("Witches abroad", Genre.Fantasy, 301);
someBookstore.Add(witchesAbroad);
var hatFullOfSky = new Book("Hat full of sky", Genre.Fantasy, 310);
someBookstore.Add(hatFullOfSky);
var gameOfThrones = new Book("Game of thrones", Genre.Fantasy, 900);
someBookstore.Add(gameOfThrones);
var deathOnTheNile = new Book("Death on the Nile", Genre.Crime, 400);
someBookstore.Add(deathOnTheNile);
var historyOfTheBalkans = new Book("History of the Balkans", Genre.History, 1120);
someBookstore.Add(historyOfTheBalkans);
Console.WriteLine(someBookstore);
var ruleOnlyFantasy = new ExpressionSpecification<Book>(b => b.Genre == Genre.Fantasy);
var ruleLargeBooks = new ExpressionSpecification<Book>(b => b.Pages > 1000);
var rulePagesBelow500 = new ExpressionSpecification<Book>(b => b.Pages < 500);
var ruleFantasyOrLargeBooks = ruleOnlyFantasy.Or(ruleLargeBooks);
var allBooks = someBookstore.All();
var largeBooks = allBooks.FindAll(b => ruleLargeBooks.IsSatisfiedBy(b));
Console.WriteLine("Large books:");
foreach (var book in largeBooks)
{
Console.WriteLine(book);
}
Console.WriteLine();
var fantasyAndLargeBooks = allBooks.FindAll(b => ruleFantasyOrLargeBooks.IsSatisfiedBy(b));
Console.WriteLine("Fantasy and large books:");
foreach (var book in fantasyAndLargeBooks)
{
Console.WriteLine(book);
}
Console.WriteLine();
}
示例2: Main
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();
}
示例3: ExpressionSpecification_IsSatisfiedBy_Success
public void ExpressionSpecification_IsSatisfiedBy_Success()
{
var spec = new ExpressionSpecification<Product>(x => x.Id == 10);
Assert.True(spec.IsSatisfiedBy(_product));
}
示例4: IsSatisfiedByTestCase1
public void IsSatisfiedByTestCase1()
{
var target = new ExpressionSpecification<String>( x => x.Length > 5 );
var actual = target.IsSatisfiedBy( "123456" );
Assert.IsTrue( actual );
}