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


C# System.Linq.Any方法代码示例

本文整理汇总了C#中System.Linq.Any方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.Any方法的具体用法?C# System.Linq.Any怎么用?C# System.Linq.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Linq的用法示例。


在下文中一共展示了System.Linq.Any方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ThenNoRoutesFollowTheRoutesFromTheController

        public void ThenNoRoutesFollowTheRoutesFromTheController(string controllerName)
        {
            var count = 0;
            var indexOfLastRouteForController = 0;
            var routes = RouteTable.Routes.Cast<Route>();

            foreach (var route in routes.ToList())
            {
                var routeControllerName = route.Defaults["controller"].ToString();
                var skipControllerNames = new[]
                {
                    "RoutePrecedenceAmongTheSitesRoutes",
                    "RoutePrecedenceViaRouteProperties"
                };

                if (skipControllerNames.Any(routeControllerName.EndsWith))
                {
                    // Skip the controllers that will come after controllers registered through the config object
                    // due to have actions that specify a SitePrecedence property.
                    continue;
                }

                if (routeControllerName == controllerName)
                    indexOfLastRouteForController = count;

                count++;
            }

            Assert.That(indexOfLastRouteForController, Is.EqualTo(count - 1));
        }
开发者ID:Cefa68000,项目名称:AttributeRouting,代码行数:30,代码来源:RoutePrecedenceSteps.cs

示例2: IfEitherIsEmptyReturnTheOtherOrEmpty

		private static bool IfEitherIsEmptyReturnTheOtherOrEmpty(QueryContainer leftContainer, QueryContainer rightContainer, out QueryContainer queryContainer)
		{
			var combined = new[] {leftContainer, rightContainer};
			var any = combined.Any(bf => bf == null || bf.IsConditionless);
			queryContainer = any ? combined.FirstOrDefault(bf => bf != null && !bf.IsConditionless) : null;
			return any;
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:7,代码来源:QueryContainer-Dsl.cs

示例3: IsTextFileType

 static bool IsTextFileType(string name)
 {
     var imageFileTypes = new[]
     {
         ".txt"
     };
     return imageFileTypes.Any(name.EndsWith);
 }
开发者ID:RickeyWard,项目名称:Shapeshifter,代码行数:8,代码来源:FileTypeInterpreter.cs

示例4: IsImageFileType

 static bool IsImageFileType(string name)
 {
     var imageFileTypes = new[]
     {
         ".png",
         ".jpg"
     };
     return imageFileTypes.Any(name.EndsWith);
 }
开发者ID:RickeyWard,项目名称:Shapeshifter,代码行数:9,代码来源:FileTypeInterpreter.cs

示例5: OK1

        // 比較していない場合はOK
        public static object OK1()
        {
            var test = new[] { "a", "b", }.Where(s => s.StartsWith("a"));
            if (test.Any())
            {
                return test;
            }

            return null;
        }
开发者ID:lavn0,项目名称:CodeAnalysis,代码行数:11,代码来源:AvoidNonNullMethodResultComparedByNullSample.cs

示例6: ContactFormEntryCreating

        public void ContactFormEntryCreating(ContactFormCreatingContext context)
        {
            var text = context.ContactFormEntry.As<BodyPart>().Text;
            var spamTerms = new[] { "viagra", "opportunity", "win!" };

            if (!spamTerms.Any(text.Contains))
                return;

            context.Cancel = true;
            _notifier.Warning(T("Your message is rated as spam and therefore not delivered."));
        }
开发者ID:sfmskywalker,项目名称:OrchardDevToolbelt,代码行数:11,代码来源:SpamProtectedContactFormEventHandler.cs

示例7: Import_RestFiles_into_S3

        public void Import_RestFiles_into_S3()
        {
            var fs = new FileSystemVirtualPathProvider(appHost, "~/restfiles".MapHostAbsolutePath());
            var skipDirs = new[] { "restfiles/files" };

            foreach (var file in fs.GetAllFiles())
            {
                if (skipDirs.Any(x => file.VirtualPath.StartsWith(x))) continue;
                s3.WriteFile(file, "restfiles/files".CombineWith(file.VirtualPath));
            }
        }
开发者ID:ServiceStackApps,项目名称:AwsApps,代码行数:11,代码来源:AdminTasks.cs

示例8: IsVersionInsertPresent

        // ReSharper disable UnusedParameter.Local
        /// <summary>
        /// Checks if script makes insert into version history table
        /// </summary>
        public static bool IsVersionInsertPresent(DbVersion dbVersion, string script)
        {
            var versionInsertRegexes =
            new[] {
              string.Format("insert\\s+(into)?\\s+\\[?version(history)?\\]?(.+?){0}\\.{1}{2}{3}", dbVersion.Major, dbVersion.Minor, RevisionRegex(dbVersion), BuildRegex(dbVersion)),
              string.Format("insert\\s+into\\s+#temp(.+?)VALUES(.*?){0}\\.{1}{2}{3}", dbVersion.Major, dbVersion.Minor, RevisionRegex(dbVersion), BuildRegex(dbVersion)),
            }
              .Select(pattern => new Regex(pattern, RegexOptions.IgnoreCase));

              return versionInsertRegexes.Any(r => r.IsMatch(script));
        }
开发者ID:pawel-sarzynski,项目名称:UberDeployer,代码行数:15,代码来源:DbScriptToRun.cs

示例9: BonusMultiplierIsCalledCorrectNumberOfTimes

        public void BonusMultiplierIsCalledCorrectNumberOfTimes()
        {
            _scorer.Register(new Strike());
            _scorer.Register(new Spare());
            _scorer.Register(new NormalRoll());

            var rollTypes = new[] {RollTypes.Strike, RollTypes.Spare, RollTypes.Normal};

            var _ = _bonusMultiplier.Received(3).Current;
            _bonusMultiplier.Received(3).Register(Arg.Is<RollTypes>(t => rollTypes.Any(t_ => t_ == t)));
            _bonusMultiplier.DidNotReceive().Register(RollTypes.Bonus);
        }
开发者ID:kalotay,项目名称:BowlingKata,代码行数:12,代码来源:ScorerTests.cs

示例10: ContactFormEntryCreating

        public void ContactFormEntryCreating(ContactFormCreatingContext context)
        {
            var text = context.ContactFormEntry.As<BodyPart>().Text;
            var spamTerms = new[] { "viagra", "opportunity", "win!", "win", "$$$", "Lose weight", "Extra income", "Money making", "Earn $", "Save $" };

            if (!spamTerms.Any(text.Contains))
            {
                _notifier.Information(T("Bericht geaccepteerd"));
                return;
            }

            context.Cancel = true;
            _notifier.Warning(T("Uw bericht is als spam beoordeeld en is daarom niet verstuurd."));
        }
开发者ID:SeyDutch,项目名称:Gilde,代码行数:14,代码来源:SpamProtectionFormEventHandler.cs

示例11: Execute

        public void Execute()
        {
            var numbers = new[] {1, 2, 3};

            //
            // Any拡張メソッドは、一つでも条件に当てはまるものが存在するか否かを判別するメソッドである。
            // この拡張メソッドは、引数無しのバージョンと引数にpredicateを渡すバージョンの2つが存在する。
            //
            // 引数を渡さずAny拡張メソッドを呼んだ場合、Any拡張メソッドは
            // 該当シーケンスに要素が存在するか否かのみで判断する。
            // つまり、要素が一つでも存在する場合は、Trueとなる。
            //
            // 引数にpredicateを指定するバージョンは、シーケンスの各要素に対してpredicateを適用し
            // 一つでも条件に合致するものが存在した時点で、Trueとなる。
            //
            Output.WriteLine("=========== 引数無しでAny拡張メソッドを利用 ===========");
            Output.WriteLine("要素有り? = {0}", numbers.Any());
            Output.WriteLine("================================================");

            Output.WriteLine("=========== predicateを指定してAny拡張メソッドを利用 ===========");
            Output.WriteLine("要素有り? = {0}", numbers.Any(item => item >= 5));
            Output.WriteLine("要素有り? = {0}", numbers.Any(item => item <= 5));
            Output.WriteLine("================================================================");
        }
开发者ID:devlights,项目名称:Sazare,代码行数:24,代码来源:LinqSamples39.cs

示例12: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            //these would usually come from a database, or cache.
            var categories = new[] { "restaurants", "cafes", "bistros" };

            if (values[parameterName] == null)
                return false;

            //get the category passed in to the route
            var category = values[parameterName].ToString();

            //now we check our categories, and see if it exists
            return categories.Any(x => x == category.ToLower());

            // url such as /category1/whatever will match
            // url such as /category4/whatever will not
        }
开发者ID:alexjamesbrown,项目名称:aspnet-DynamicRouteExample,代码行数:17,代码来源:CategoryRouteConstraint.cs

示例13: ConvertTextForSEOURL

        public static string ConvertTextForSEOURL(string inputText)
        {
            if (string.IsNullOrEmpty(inputText))
            {
                return string.Empty;
            }

            var charsForRepl = new [] { 'á', 'č', 'ď', 'é', 'ě', 'í', 'ň', 'ó', 'ř', 'š', 'ť', 'ú', 'ů', 'ý', 'ž', ' ' };
            var charsToRepl = new [] { 'a', 'c', 'd', 'e', 'e', 'i', 'n', 'o', 'r', 's', 't', 'u', 'u', 'y', 'z', '-' };
            var charsNotAllowed = new [] { '"', '~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '=', '+', '[', ']', '{', '}', '|', '<', '>', ',', '.', '/', '?', '\'', '\\', ':', '\r', '\n' };

            inputText = inputText.ToLower();

            var retText = "";

            for (var i = 0; i < inputText.Length; i++)
            {
                bool wasReplace = false;
                bool doSkip = charsNotAllowed.Any(c => inputText[i] == c);

                for (var j = 0; j < charsForRepl.Length; j++)
                {
                    if (inputText[i] == charsForRepl[j])
                    {
                        retText = retText + charsToRepl[j];
                        wasReplace = true;
                        break;
                    }
                }

                if (!doSkip && !wasReplace)
                {
                    retText = retText + inputText[i];
                }
            }

            return retText;
        }
开发者ID:senseicz,项目名称:Galerie-KusVola,代码行数:38,代码来源:SEO.cs

示例14: OK3

        // 一部のパスでインスタンスがある場合は、OK
        public static bool OK3(bool flg)
        {
            var sequence = new[] { "1", "2", "3", }.Where(e => e is string);
            if (flg)
            {
                sequence = new[] { "1", "2", "3", }.ToList();
            }

            if (sequence != null)
            {
                return sequence.Any();
            }

            return false;
        }
开发者ID:lavn0,项目名称:CodeAnalysis,代码行数:16,代码来源:AvoidNonNullMethodResultComparedByNullSample.cs

示例15: Generate35

		private static void Generate35(string srcPath, string destFile, params string[] references)
		{
			var database = XDocument.Load(srcPath);
			foreach (var element in database.Root.Descendants(xmlns + "DefineConstants").ToArray())
			{
				if (element.Value.EndsWith(";") == false)
					element.Value += ";";
				element.Value += "NET35";
			}

			foreach (var element in database.Root.Descendants(xmlns + "ProjectReference").ToArray())
			{
				if (references.Contains(element.Element(xmlns + "Name").Value) == false)
					continue;
				element.Attribute("Include").Value = element.Attribute("Include").Value.Replace(".csproj", ".g.3.5.csproj");
				{
					element.Element(xmlns + "Project").Value = "{4C18FC25-0B1E-42E3-A423-3A99F1AC57EE}";
					element.Element(xmlns + "Name").Value += "-3.5";
				}
			}

			foreach (var element in database.Root.Descendants(xmlns + "Reference").ToArray())
			{
				if (element.Attribute("Include").Value == "Microsoft.CSharp")
					element.Remove();
				if (element.Attribute("Include").Value == "AsyncCtpLibrary")
					element.Remove();
				if (element.Attribute("Include").Value == "System.ComponentModel.Composition")
					element.Remove();

				var nugetPakcages = new[] {"Newtonsoft.Json", "NLog"};
				if (nugetPakcages.Any(x => element.Attribute("Include").Value.StartsWith(x)))
				{
					element.Element(xmlns + "HintPath").Value = element.Element(xmlns + "HintPath").Value.Replace("net40", "net35");
				}
			}

			foreach (var element in database.Root.Descendants(xmlns + "DocumentationFile").ToArray())
			{
				element.Value = element.Value.Replace(".XML", "-3.5.XML");
			}
			foreach (var element in database.Root.Descendants(xmlns + "TargetFrameworkVersion"))
			{
				element.Value = "v3.5";
			}
			foreach (var element in database.Root.Descendants(xmlns + "TargetFrameworkProfile"))
			{
				element.Value = "Client";
			}
			foreach (var element in database.Root.Descendants(xmlns + "AssemblyName"))
			{
				element.Value += "-3.5";
			}
			using (var xmlWriter = XmlWriter.Create(destFile,
													new XmlWriterSettings
													{
														Indent = true
													}))
			{
				database.WriteTo(xmlWriter);
				xmlWriter.Flush();
			}
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:63,代码来源:Program.cs


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