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


C# Stack.All方法代码示例

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


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

示例1: StackExtensions_All_ReturnsTrueIfStackIsEmpty

        public void StackExtensions_All_ReturnsTrueIfStackIsEmpty()
        {
            var stack = new Stack<Int32>();

            var result = stack.All(x => x % 2 == 0);

            TheResultingValue(result).ShouldBe(true);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:8,代码来源:StackExtensionsTest.cs

示例2: StackExtensions_All_ReturnsTrueIfAllItemsMatchPredicate

        public void StackExtensions_All_ReturnsTrueIfAllItemsMatchPredicate()
        {
            var stack = new Stack<Int32>();
            stack.Push(2);
            stack.Push(4);
            stack.Push(6);

            var result = stack.All(x => x % 2 == 0);

            TheResultingValue(result).ShouldBe(true);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:11,代码来源:StackExtensionsTest.cs

示例3: StackExtensions_All_ReturnsFalseIfOneItemDoesNotMatchPredicate

        public void StackExtensions_All_ReturnsFalseIfOneItemDoesNotMatchPredicate()
        {
            var stack = new Stack<Int32>();
            stack.Push(1);
            stack.Push(2);
            stack.Push(4);
            stack.Push(6);

            var result = stack.All(x => x % 2 == 0);

            TheResultingValue(result).ShouldBe(false);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:12,代码来源:StackExtensionsTest.cs

示例4: CheckEach

 public static bool CheckEach(this List<Filter> filters, ITwitterItem item)
 {
     Stack<Tuple<bool, int>> results = new Stack<Tuple<bool, int>>();
     for (int i = 0; i < filters.Count - 1; i++)
     {
         if (results.Count == 0 || results.Peek().Item2 < filters[i].Level)
         {
             results.Push(Tuple.Create(filters[i].Process(item), filters[i].Level));
         }
         else if (results.Peek().Item2 == filters[i].Level)
         {
             var t = results.Pop();
             if (filters[i].AndCombine)
             {
                 results.Push(Tuple.Create(t.Item1 && filters[i].Process(item), filters[i].Level));
             }
             else
             {
                 results.Push(Tuple.Create(t.Item1 || filters[i].Process(item), filters[i].Level));
             }
         }
         else
         {
             bool r = filters[i].Process(item);
             if (filters[i].AndCombine)
             {
                 do
                 {
                     r = r && results.Pop().Item1;
                 } while (results.Count == 0 || results.Peek().Item2 >= filters[i].Level);
             }
             else
             {
                 do
                 {
                     r = r || results.Pop().Item1;
                 } while (results.Count == 0 || results.Peek().Item2 >= filters[i].Level);
             }
             results.Push(Tuple.Create(r, filters[i].Level));
         }
     }
     if (filters.Last().AndCombine)
     {
         results.Push(Tuple.Create(filters.Last().Process(item), filters.Last().Level));
         return results.All(t => t.Item1);
     }
     else
     {
         results.Push(Tuple.Create(filters.Last().Process(item), filters.Last().Level));
         return results.Any(t => t.Item1);
     }
     //return false;
 }
开发者ID:iyomumx,项目名称:MiniTwitter-Mod,代码行数:53,代码来源:FiltersExtension.cs

示例5: FilterSchemaDirectives

        private static IEnumerable<string> FilterSchemaDirectives(IEnumerable<string> C7Schema)
        {
            var directiveValues = new HashSet<string>();
            var state = new Stack<Func<HashSet<string>, bool>>();
            var status = true;

            foreach (var originalLine in C7Schema)
            {
                var line = originalLine.Trim();

                if (line.Length > 1 && line[0] == '#')
                {
                    if (line.StartsWith("#COMPILE"))
                    {
                        // Add directive
                        var directive = line.Substring(8, line.IndexOf(';') - 8).Trim();

                        // Override for CHESS (eduHub is always CHESS)
                        if (directive == "NOCHESS")
                        {
                            directive = "CHESS";
                        }

                        directiveValues.Add(directive);
                    }
                    else if (line.StartsWith("#IF"))
                    {
                        string directive;
                        var terminator = line.IndexOf(';');
                        if (terminator > 0)
                        {
                            directive = line.Substring(4, terminator - 4);
                        }
                        else
                        {
                            directive = line.Substring(4);
                        }

                        var directives = directive.Split('|').Select(d => d.Trim()).ToList();

                        if (directives.Count == 0)
                        {
                            throw new InvalidOperationException("Invalid schema command");
                        }

                        // Push to state
                        state.Push(values => values.Any(v => directives.Any(d => v == d)));
                    }
                    else if (line.StartsWith("#ELSE"))
                    {
                        // Push inverse to state
                        var directive = state.Pop();
                        // Inverse
                        state.Push(values => !directive(values));
                    }
                    else if (line.StartsWith("#ENDIF"))
                    {
                        // Pop state
                        var directive = state.Pop();
                    }
                    else if (status)
                    {
                        yield return originalLine;
                    }

                    status = state.Count == 0 || state.All(s => s(directiveValues));
                }
                else if (status)
                {
                    yield return originalLine;
                }
            }
        }
开发者ID:Stalinko,项目名称:EduHub.Data,代码行数:73,代码来源:C7Parser.cs

示例6: CreateCode

		public void CreateCode(object sender, EventArgs args)
		{
			var templateFile = Path.Combine ((@"CTool"+  Path.DirectorySeparatorChar), "CodeTemplate.c").GetAbsolutePath ();
			string template = System.IO.File.ReadAllText (templateFile);

			string variables = string
				.Join(
					Environment.NewLine,
					AppController
					.Instance
					.GetUserVariablesWithDefault()
					.Select(v => string.Format("unsigned long {0};", v)));
			
			template = template.Replace("#{UserVariables}", variables);

			var workflow = new StringBuilder ();
			// function sequence alhorithm.

			var surface = AppController.Instance.Surface;

			var segments = surface.Get ();

			var queue = new Stack<Segment> ();
			string comment;
			queue.Push(segments
				.FirstOrDefault (s => {
					var rule = s.Type.GetRuleForElement();
					if(rule != null)
					{
						var func = rule.Resolve(s, out comment); 
						return func == FunctionType.In || 
							func == FunctionType.InAnalog || 
							func == FunctionType.InNot || 
							func == FunctionType.TimerOff ||
							func == FunctionType.TimerOn ||
							func == FunctionType.TimerCycle ||
							func == FunctionType.TimerPulse ||
							func == FunctionType.Latch ||
							func == FunctionType.LatchKey;
					}
					return false;
				}));

			var parsed = new List<Segment> ();

			while (queue.Any()) {
				var current = queue.Pop ();

				if (current == null) {
					continue;
				}

				//do not use already parsed elements in workflow.
				if (parsed.Any (p => p.Identifier == current.Identifier)) {
					continue;
				}

				// add connected segments to queue.
				var siblings = current
					.Connectors
					.SelectMany(con => con
						.ConnectedTo
						.ToList ()
						.Select (id => segments.FirstOrDefault(s => s.Identifier.ToString() == id)))
					.Where(s => s != null && 
						parsed.All(p => p.Identifier != s.Identifier) &&
						queue.All(p => p.Identifier != s.Identifier))
					.ToList(); // exclude already parsed segments.

				var childQueue = new Stack<Segment> ();

				siblings
					.Where (s => s.Position.X <= current.Position.X)
					.ToList()
					.ForEach(childQueue.Push);

				siblings
					.Where (s => s.Type == ElementType.Latch)
					.ToList ()
					.ForEach (s2 => {
						if (s2.Join.Any()) { // add connected segments to joined segment in latch
							s2.Join.ForEach (c1 => {
								var s1 = c1.Connectors
									.SelectMany (con => con
										.ConnectedTo
										.Select (id => segments.FirstOrDefault (s => s.Identifier.ToString () == id)))
									.Where (s => s != null &&
										s.Position.X < s2.Position.X &&
										parsed.All(p => p.Identifier != s.Identifier) &&
										queue.All(p => p.Identifier != s.Identifier))
									.ToList (); // exclude already parsed segments.

								var latchQueue = new Stack<Segment>();
								s1.ForEach(latchQueue.Push);
								var latchParsed = new List<Segment> ();

								latchParsed.Add(c1); // do not use joined element in child loop
								PushChild(latchQueue, 
									segments, 
									parsed, 
//.........这里部分代码省略.........
开发者ID:jdpillon,项目名称:ArduinoLadder,代码行数:101,代码来源:CController.cs

示例7: PushChild

		private void PushChild(Stack<Segment> childQueue, 
			IEnumerable<Segment> segments, 
			List<Segment> parsed, 
			List<Segment> childParsed,
			Stack<Segment> queue,
			Segment current)
		{
			while (childQueue.Any()) {
				var child = childQueue.Pop ();

				var childSiblings = child
					.Connectors
					.SelectMany(con => con
						.ConnectedTo
						.ToList ()
						.Select (id => segments.FirstOrDefault(s => s.Identifier.ToString() == id)))
					.Where(s => s!= null && 
						parsed.All(p => p.Identifier != s.Identifier) &&
						childParsed.All(p => p.Identifier != s.Identifier) &&
						queue.All(p => p.Identifier != s.Identifier) &&
						child.Position.X < s.Position.X &&
						current.Identifier != s.Identifier
					).ToList();

				if (child.Join.Any()) { // add connected segments to joined segment in latch
					child.Join.ForEach (c1 => {
						var s1 = c1.Connectors
							.SelectMany (con => con
								.ConnectedTo
								.ToList ()
								.Select (id => segments.FirstOrDefault (s => s.Identifier.ToString () == id)))
							.Where (s => s != null &&
								parsed.All(p => p.Identifier != s.Identifier) &&
								queue.All(p => p.Identifier != s.Identifier))
							.ToList (); // exclude already parsed segments.
						var latchQueue = new Stack<Segment>();
						s1.ForEach(latchQueue.Push);
						var latchParsed = new List<Segment> ();
						PushChild(latchQueue, 
							segments, 
							parsed, 
							latchParsed,
							queue,
							current);

						latchParsed.ForEach(childQueue.Push);
					});
				}

				childSiblings.ForEach (childQueue.Push);
				childParsed.Add (child);
			}
		}
开发者ID:jdpillon,项目名称:ArduinoLadder,代码行数:53,代码来源:CController.cs

示例8: Stream

        public static IEnumerable<Token> Stream(string fileName, DelphiIncludeResolver resolver, string[] symbols)
        {
            Stack<Tuple<DirectiveKind, string, bool>> openedIfs = new Stack<Tuple<DirectiveKind, string, bool>>();

            foreach (var token in StreamSingleFile(fileName).Where(t => t.Kind != TokenKind.Comment)) {
                if (token.Kind == TokenKind.Directive) {
                    string[] parameters;
                    string symbol;
                    var directiveKind = ParseDirective(token.Value, out parameters);
                    switch (directiveKind) {
                        case DirectiveKind.Include:
                            // possible stack overflow: optimize!
                            string fileNamePart = parameters.FirstOrDefault();
                            if (string.IsNullOrWhiteSpace(fileNamePart))
                                break;
                            string fullName = resolver.ResolveFileName(fileNamePart, fileName);
                            if (fullName == null)
                                break;
                            foreach (var nestedToken in Stream(fullName, resolver, symbols)) {
                                yield return nestedToken;
                            }
                            break;
                        case DirectiveKind.IfDef:
                            symbol = parameters.FirstOrDefault();
                            if (!string.IsNullOrWhiteSpace(symbol) && symbol[0] == '!') {
                                bool include = !symbols.Contains(symbol.Substring(1));
                                openedIfs.Push(Tuple.Create(DirectiveKind.IfNDef, symbol.Substring(1), include));
                            } else {
                                bool include = symbols.Contains(symbol);
                                openedIfs.Push(Tuple.Create(DirectiveKind.IfDef, symbol, include));
                            }
                            break;
                        case DirectiveKind.IfNDef:
                            symbol = parameters.FirstOrDefault();
                            if (!string.IsNullOrWhiteSpace(symbol) && symbol[0] == '!') {
                                bool include = symbols.Contains(symbol.Substring(1));
                                openedIfs.Push(Tuple.Create(DirectiveKind.IfDef, symbol.Substring(1), include));
                            } else {
                                bool include = !symbols.Contains(symbol);
                                openedIfs.Push(Tuple.Create(DirectiveKind.IfNDef, symbol, include));
                            }
                            break;
                        case DirectiveKind.Else:
                            if (openedIfs.Count > 0) {
                                var old = openedIfs.Pop();
                                openedIfs.Push(Tuple.Create(old.Item1, old.Item2, !old.Item3));
                            }
                            break;
                        case DirectiveKind.EndIf:
                            if (openedIfs.Count > 0)
                                openedIfs.Pop();
                            break;
                    }
                } else {
                    if (openedIfs.Count == 0 || openedIfs.All(i => i.Item3))
                        yield return token;
                }
            }
        }
开发者ID:psVenture,项目名称:usalizer,代码行数:59,代码来源:DelphiTokenStream.cs

示例9: Execute

        public int Execute(object handle)
        {
            var instructions = (List<ParsedInstruction>) handle;

            var protobuild = Assembly.GetEntryAssembly().Location;
            var workingDirectory = _workingDirectoryProvider.GetPath();

            var targets = string.Empty;
            var buildTarget = string.Empty;
            var buildProcessArch = string.Empty;
            var buildProperties = new Dictionary<string, string>();
            string executeConfiguration = null;

            var predicates = new Stack<ParsedInstruction>();
            foreach (var inst in instructions)
            {
                if (inst.Predicate != null)
                {
                    predicates.Push(inst);
                }
                else if (inst.EndPredicate)
                {
                    predicates.Pop();
                }
                else if (predicates.All(x => x.Predicate()))
                {
                    if (inst.Command == "native-execute")
                    {
                        var components = inst.Arguments.Split(new[] {' '}, 2);

                        string path;
                        try
                        {
                            path = FindNativeProgram(components[0]);
                        }
                        catch (ApplicationException ex)
                        {
                            Console.Error.WriteLine(ex);
                            return 1;
                        }

                        var args = components.Length == 2 ? components[1] : string.Empty;

                        Console.WriteLine("+ native-execute " + path + " " + args);
                        var process =
                            Process.Start(new ProcessStartInfo(path, args)
                            {
                                WorkingDirectory = workingDirectory,
                                UseShellExecute = false
                            });
                        if (process == null)
                        {
                            Console.Error.WriteLine("ERROR: Process did not start when running " + path + " " +
                                args);
                            return 1;
                        }
                        process.WaitForExit();
                        if (process.ExitCode != 0)
                        {
                            Console.Error.WriteLine(
                                "ERROR: Non-zero exit code " + process.ExitCode);
                            return process.ExitCode;
                        }
                    }
                    else if (inst.Command == "nuget")
                    {
                        // See if we have a copy of NuGet available for use.
                        var cachedNuget =
                            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                "NuGet.exe");
                        if (!File.Exists(cachedNuget))
                        {
                            var client = new WebClient();
                            client.DownloadFile("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", cachedNuget);
                        }

                        string runtime = null;
                        var hostPlatform = _hostPlatformDetector.DetectPlatform();
                        if (hostPlatform != "Windows")
                        {
                            try
                            {
                                runtime = FindNativeProgram("mono");
                            }
                            catch (ApplicationException ex)
                            {
                                Console.Error.WriteLine(ex);
                                return 1;
                            }
                        }

                        Process process;

                        if (hostPlatform != "Windows" && runtime != null)
                        {
                            Console.WriteLine("+ " + runtime + " \"" + cachedNuget + "\" " + inst.Arguments);
                            process =
                                Process.Start(new ProcessStartInfo(runtime, "\"" + cachedNuget + "\" " + inst.Arguments)
                                {
                                    WorkingDirectory = workingDirectory,
//.........这里部分代码省略.........
开发者ID:marler8997,项目名称:Protobuild,代码行数:101,代码来源:AutomatedBuildRuntimeV1.cs

示例10: ParseChunk

        public static IList<ParsedChunk> ParseChunk(string input)
        {
            #region init

            // init
            var toReturn = new List<ParsedChunk>();
            var openTags = new Stack<BbTag>();
            var tags = new Queue<BbTag>();
            var processedQueue = new Queue<BbTag>();

            var finder = new BbFinder(input);

            // find all tags
            while (!finder.HasReachedEnd)
            {
                var next = finder.Next();
                if (next != null)
                    tags.Enqueue(next);
            }


            // return original input if we've no valid bbcode tags
            if (tags.All(x => x.Type == BbCodeType.None))
                return new[] {AsChunk(input)};

            #endregion

            while (tags.Count > 0)
            {
                // get the next tag to process
                var tag = tags.Dequeue();
                var addToQueue = true;

                #region add as child of last tag

                // check if we're in the context of another open tag
                if (openTags.Count > 0)
                {
                    var lastOpen = openTags.Peek();
                    var lastMatching = openTags.FirstOrDefault(x => tag.IsClosing && x.Type == tag.Type);

                    // check if we're closing any previous tags
                    if (lastMatching != null)
                    {
                        lastMatching.ClosingTag = tag;

                        // keep going through our opened tag stack until we find the one
                        // we're closing
                        do
                        {
                            lastOpen = openTags.Pop();

                            // if we end up with a tag that isn't the one we're closing,
                            // it must not have been closed correctly, e.g
                            // [i] [b] [/i]
                            // we'll treat that '[b]' as text
                            if (lastOpen != lastMatching) lastOpen.Type = BbCodeType.None;
                        } while (lastOpen != lastMatching);

                        #region handle noparse

                        if (lastMatching.Type == BbCodeType.NoParse)
                        {
                            lastMatching.Children = lastMatching.Children ?? new List<BbTag>();
                            lastMatching.Children.Add(new BbTag
                            {
                                Type = BbCodeType.None,
                                End = tag.Start,
                                Start = lastMatching.End
                            });
                        }

                        #endregion
                    }
                    else
                    {
                        if (openTags.All(x => x.Type != BbCodeType.NoParse))
                        {
                            // if not, we have to be a child of it
                            lastOpen.Children = lastOpen.Children ?? new List<BbTag>();

                            lastOpen.Children.Add(tag);
                        }

                        // any matching closing tags would be caught in the if part of this
                        // branch, this is an invalid tag, treat as text
                        if (tag.IsClosing) tag.Type = BbCodeType.None;

                        addToQueue = false;
                    }
                }

                #endregion

                // we don't need to continue processing closing tags
                if (tag.IsClosing) continue;

                // tell the system we're in the context of this tag now
                // though ignore children of 'text' and 'hr'
                if (tag.Type != BbCodeType.None && tag.Type != BbCodeType.HorizontalRule)
//.........这里部分代码省略.........
开发者ID:ZornTaov,项目名称:slimCat,代码行数:101,代码来源:BbCodeBaseConverter.cs


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