当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionSpecification.IsSatisfiedBy方法代码示例

本文整理汇总了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();
        }
开发者ID:DennyGD,项目名称:High-Quality-Code,代码行数:42,代码来源:Demo.cs

示例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();
        }
开发者ID:beginor,项目名称:DesignPatterns,代码行数:20,代码来源:Program.cs

示例3: ExpressionSpecification_IsSatisfiedBy_Success

 public void ExpressionSpecification_IsSatisfiedBy_Success()
 {
     var spec = new ExpressionSpecification<Product>(x => x.Id == 10);
     Assert.True(spec.IsSatisfiedBy(_product));
 }
开发者ID:hightechtoday,项目名称:costeffectivecode,代码行数:5,代码来源:SpecificationTests.cs

示例4: IsSatisfiedByTestCase1

 public void IsSatisfiedByTestCase1()
 {
     var target = new ExpressionSpecification<String>( x => x.Length > 5 );
     var actual = target.IsSatisfiedBy( "123456" );
     Assert.IsTrue( actual );
 }
开发者ID:MannusEtten,项目名称:Extend,代码行数:6,代码来源:ExpressionSpecification.Test.cs


注:本文中的ExpressionSpecification.IsSatisfiedBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。