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


C# Stack.PopOrDefault方法代码示例

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


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

示例1: PopOrDefaultTest

 public void PopOrDefaultTest()
 {
     var stack = new Stack<int>(new[] { 1, 2 });
     Assert.AreEqual(2, stack.PopOrDefault());
     Assert.AreEqual(1, stack.PopOrDefault());
     Assert.AreEqual(0, stack.PopOrDefault());
 }
开发者ID:Kladzey,项目名称:RynokEngine,代码行数:7,代码来源:ExtensionsTests.cs

示例2: DoPrimaryDecompilation

        private void DoPrimaryDecompilation()
        {
            var loopholes = new List<Loophole>();
            Func<Loophole> emit_loophole = () =>
            {
                var loophole = new Loophole();
                loopholes.Add(loophole);
                return loophole;
            };

            _stack = new Stack<Expression>();
            foreach (var op in _cil)
            {
                _currentOp = op;
                _args = op.OpSpec.Pops.Times(_ =>
                    _stack.PopOrDefault() ?? emit_loophole()
                ).Reverse().ToReadOnly();

                Dispatch(op);

                if (_stack.IsEmpty() && _qualified.IsNotEmpty())
                {
                    var fixt = FixupEvaluationOrder(_qualified.ToReadOnly());
                    fixt.ForEach(q => _block.BalancedCode.Add(q));
                    _qualified.Clear();
                }
            }

            var pending = _qualified.Concat(_stack.Reverse().Cast<Node>()).ToReadOnly();
            if (pending.IsNotEmpty())
            {
                var p_fixt = FixupEvaluationOrder(pending);
                Func<Node, int> stackBalance = n => 
                    !(n is Expression) ? 0 :
                    n is Assign ? 0 :
                    n is Eval ? (n.InvokedMethod().Ret() == typeof(void) ? 0 : 1) :
                    /* otherwise */ 1;;
                var delim = 0.UpTo(p_fixt.Count() - 1).Single(i =>
                    p_fixt.Take(i).All(n => stackBalance(n) == 0) &&
                    p_fixt.Skip(i).All(n => stackBalance(n) == 1));
                p_fixt.Take(delim).ForEach(p => _block.BalancedCode.Add(p));
                p_fixt.Skip(delim).ForEach(p => _block.Residue.Add(p.AssertCast<Expression>()));
                _qualified.Clear();
            }

            loopholes.Reverse();
            loopholes.ForEach((l, i) => l.Tag = i);
        }
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:48,代码来源:InitialDecompilation.cs

示例3: ApplyToRange

		static void ApplyToRange(ITextEditor editor, Stack<string> indentation, int begin, int end, int selBegin, int selEnd)
		{
			bool multiLine = false;
			
			for (int i = begin; i <= end; i++) {
				IDocumentLine curLine = editor.Document.GetLine(i);
				string lineText = curLine.Text.TrimStart(' ', '\t', '\r', '\n');
				string noComments = lineText.TrimComments().TrimEnd(' ', '\t', '\r', '\n');
				
				if (i < selBegin || i > selEnd) {
					indentation.PopOrDefault();
					indentation.Push(DocumentUtilitites.GetWhitespaceAfter(editor.Document, curLine.Offset));
				}
				
				// change indentation before (indent this line)
				if (multiLine && noComments.EndsWith("}", StringComparison.OrdinalIgnoreCase)) {
					Unindent(indentation);
					multiLine = false;
				}
				
				editor.Document.SmartReplaceLine(curLine, (indentation.PeekOrDefault() ?? string.Empty) + lineText);
				
				// change indentation afterwards (indent next line)
				if (!multiLine && noComments.EndsWith("_", StringComparison.OrdinalIgnoreCase)) {
					Indent(editor, indentation);
					multiLine = true;
				}

				if (multiLine && !noComments.EndsWith("_", StringComparison.OrdinalIgnoreCase)) {
					multiLine = false;
					Unindent(indentation);
				}
			}
		}
开发者ID:siegfriedpammer,项目名称:SharpDevelop,代码行数:34,代码来源:VBNetFormattingStrategy.cs

示例4: Unindent

		static void Unindent(Stack<string> indentation)
		{
			indentation.PopOrDefault();
		}
开发者ID:siegfriedpammer,项目名称:SharpDevelop,代码行数:4,代码来源:VBNetFormattingStrategy.cs

示例5: ApplyToRange

		static void ApplyToRange(ITextEditor editor, Stack<string> indentation, List<int> eols, int blockStart, int blockEnd, int selectionStart, int selectionEnd, bool sawAttribute) {
			LoggingService.InfoFormatted("indenting line {0} to {1} with {2}", blockStart, blockEnd, (indentation.PeekOrDefault() ?? "").Length);
			
			int nextEol = -1;
			bool wasMultiLine = false;
			
			for (int i = blockStart; i <= blockEnd; i++) {
				IDocumentLine curLine = editor.Document.GetLine(i);
				string lineText = curLine.Text.TrimStart();
				// preprocessor directives cannot be multiline (just as comments)
				// and they are not included in normal block indentation ->
				// treat preprocessor directives as comments -> remove them
				string noComments = lineText.TrimComments().TrimPreprocessorDirectives().TrimEnd().TrimEnd('_').TrimEnd();
				
				// adjust indentation if the current line is not selected
				// lines between the selection will be aligned to the selected level
				if (i < selectionStart || i > selectionEnd) {
					indentation.PopOrDefault();
					indentation.Push(DocumentUtilitites.GetWhitespaceAfter(editor.Document, curLine.Offset));
				}
				
				// look for next eol if line is not empty
				// (the lexer does not produce eols for empty lines)
				if (!string.IsNullOrEmpty(noComments) && i >= nextEol) {
					int search = eols.BinarySearch(i);
					if (search < 0)
						search = ~search;
					nextEol = search < eols.Count ? eols[search] : i;
				}
				
				// remove indentation in last line of multiline array(, collection, object) initializers
				if (i == nextEol && wasMultiLine && (noComments == "}" || sawAttribute)) {
					wasMultiLine = false;
					Unindent(indentation);
				}
				
				// apply the indentation
				editor.Document.SmartReplaceLine(curLine, (indentation.PeekOrDefault() ?? "") + lineText);
				
				// indent line if it is ended by (implicit) line continuation
				if (i < nextEol && !wasMultiLine) {
					wasMultiLine = true;
					Indent(editor, indentation);
				}
				
				// unindent if this is the last line of a multiline statement
				if (i == nextEol && wasMultiLine) {
					wasMultiLine = false;
					Unindent(indentation);
				}
			}
		}
开发者ID:rbrunhuber,项目名称:SharpDevelop,代码行数:52,代码来源:VBNetFormattingStrategy.cs


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