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


C# Stack.TryPop方法代码示例

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


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

示例1: DeepEquals

        /// <summary>
        /// Compares two <see cref="XObject">XObjects</see>for equality.
        /// </summary>
        /// <param name="obj1">The first <see cref="XObject" />.</param>
        /// <param name="obj2">The second <see cref="XObject" />.</param>
        /// <param name="options">The comparison options.</param>
        /// <param name="stringComparer">The string comparer.</param>
        /// <returns>The <see cref="XObject"/> at which the first mismatch
        /// occurred; otherwise <see langword="null"/>.</returns>
        /// <remarks><para>The order of the parameters maters for ceratin options.</para></remarks>
        public static Tuple<XObject, XObject> DeepEquals(
            [CanBeNull] this XObject obj1,
            [CanBeNull] XObject obj2,
            XObjectComparisonOptions options = XObjectComparisonOptions.Default,
            [CanBeNull] StringComparer stringComparer = null)
        {
            if (stringComparer == null)
                stringComparer = StringComparer.CurrentCulture;

            // Normalize flags
            bool ignoreAttributes = (options & XObjectComparisonOptions.IgnoreAttributes) ==
                                    XObjectComparisonOptions.IgnoreAttributes;
            bool ignoreAdditionalAttributes = ignoreAttributes ||
                                        ((options & XObjectComparisonOptions.IgnoreAdditionalAttributes) ==
                                         XObjectComparisonOptions.IgnoreAdditionalAttributes);
            bool ignoreAttributeOrder = ignoreAdditionalAttributes ||
                                        ((options & XObjectComparisonOptions.IgnoreAttributeOrder) ==
                                         XObjectComparisonOptions.IgnoreAttributeOrder);

            bool ignoreElements = (options & XObjectComparisonOptions.IgnoreElements) ==
                                    XObjectComparisonOptions.IgnoreElements;
            bool ignoreAdditionalElements = ignoreElements ||
                                        ((options & XObjectComparisonOptions.IgnoreAdditionalElements) ==
                                         XObjectComparisonOptions.IgnoreAdditionalElements);
            bool ignoreElementOrder = ignoreAdditionalElements ||
                                        ((options & XObjectComparisonOptions.IgnoreElementOrder) ==
                                         XObjectComparisonOptions.IgnoreElementOrder);

            bool ignoreComments = (options & XObjectComparisonOptions.IgnoreComments) ==
                                    XObjectComparisonOptions.IgnoreComments;
            bool ignoreAdditionalCommentss = ignoreComments ||
                                        ((options & XObjectComparisonOptions.IgnoreAdditionalComments) ==
                                         XObjectComparisonOptions.IgnoreAdditionalComments);
            bool ignoreCommentOrder = ignoreAdditionalCommentss ||
                                        ((options & XObjectComparisonOptions.IgnoreCommentOrder) ==
                                         XObjectComparisonOptions.IgnoreCommentOrder);

            bool ignoreText = (options & XObjectComparisonOptions.IgnoreText) ==
                                    XObjectComparisonOptions.IgnoreText;
            bool ignoreAdditionalText = ignoreText || ((options & XObjectComparisonOptions.IgnoreAdditionalText) ==
                                         XObjectComparisonOptions.IgnoreAdditionalText);
            bool ignoreTextOrder = ignoreAdditionalText ||
                ((options & XObjectComparisonOptions.IgnoreTextOrder) ==
                                         XObjectComparisonOptions.IgnoreTextOrder);
            bool ignoreTextOutsideOfChildren = ignoreText || ((options & XObjectComparisonOptions.IgnoreTextOutsideOfChildren) ==
                                         XObjectComparisonOptions.IgnoreTextOutsideOfChildren);


            bool ignoreProcessingInstructions = (options & XObjectComparisonOptions.IgnoreProcessingInstructions) ==
                                    XObjectComparisonOptions.IgnoreProcessingInstructions;
            bool ignoreAdditionalProcessingInstructionss = ignoreProcessingInstructions ||
                                        ((options & XObjectComparisonOptions.IgnoreAdditionalProcessingInstructions) ==
                                         XObjectComparisonOptions.IgnoreAdditionalProcessingInstructions);
            bool ignoreProcessingInstructionOrder = ignoreAdditionalProcessingInstructionss ||
                                        ((options & XObjectComparisonOptions.IgnoreProcessingInstructionOrder) ==
                                         XObjectComparisonOptions.IgnoreProcessingInstructionOrder);

            bool ignoreDocumentTypes = (options & XObjectComparisonOptions.IgnoreDocumentTypes) ==
                                    XObjectComparisonOptions.IgnoreDocumentTypes;
            bool ignoreAdditionalDocumentTypess = ignoreDocumentTypes ||
                                        ((options & XObjectComparisonOptions.IgnoreAdditionalDocumentTypes) ==
                                         XObjectComparisonOptions.IgnoreAdditionalDocumentTypes);

            bool ignoreAllChildren = ignoreElements &&
                                     ignoreProcessingInstructions &&
                                     ignoreDocumentTypes &&
                                     ignoreComments &&
                                     ignoreText;
            bool allOrderSignificant = !ignoreElementOrder &&
                     !ignoreProcessingInstructionOrder &&
                     !ignoreCommentOrder &&
                     !ignoreTextOrder &&
                     !ignoreTextOutsideOfChildren;

            Stack<XObject, XObject> stack = new Stack<XObject, XObject>();
            stack.Push(obj1, obj2);

            while (stack.TryPop(out obj1, out obj2))
            {
                // Generic equality checks
                if (ReferenceEquals(obj1, obj2)) continue;
                if (ReferenceEquals(obj1, null) ||
                    ReferenceEquals(obj2, null) ||
                    obj1.NodeType != obj2.NodeType)
                    return new Tuple<XObject, XObject>(obj1, obj2);

                XContainer container1 = null;
                XContainer container2 = null;
                // Perform type specific checks.
                switch (obj1.NodeType)
//.........这里部分代码省略.........
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:101,代码来源:XObjectExtensions.cs

示例2: Serialize

        private static XElement Serialize([NotNull] IExpression expression)
        {
            Stack<IExpression, XElement> stack = new Stack<IExpression, XElement>();
            XElement rootElement = new XElement(expression.ExpressionType.ToString());
            stack.Push(expression, rootElement);

            XElement element;
            while (stack.TryPop(out expression, out element))
            {
                Debug.Assert(expression != null, "expression != null");
                Debug.Assert(element != null, "element != null");

                switch (expression.ExpressionType)
                {
                    case ExpressionType.Compiled:
                        ICompiledExpression compiledExpression = (ICompiledExpression) expression;
                        stack.Push(compiledExpression.RawExpression, element);
                        break;
                    case ExpressionType.Number:
                        NumberExpression numberExpression = (NumberExpression) expression;
                        element.Value = numberExpression.Value.ToString("R", _culture);
                        break;
                    case ExpressionType.Edge:
                        EdgeExpression edgeExpression = (EdgeExpression) expression;
                        element.Value = edgeExpression.EdgeName;
                        break;
                    case ExpressionType.Vertex:
                        VertexExpression vertexExpression = (VertexExpression) expression;
                        element.Value = vertexExpression.VertexName;
                        break;
                    case ExpressionType.Add:
                    case ExpressionType.Subtract:
                    case ExpressionType.Multiply:
                    case ExpressionType.Divide:
                        ArithmeticExpression arithmeticExpression = (ArithmeticExpression) expression;
                        foreach (IExpression<float> exp in arithmeticExpression.Expressions)
                        {
                            XElement elm = new XElement(exp.ExpressionType.ToString());
                            stack.Push(expression, elm);
                            element.Add(elm);
                        }
                        break;
                    case ExpressionType.Equal:
                    case ExpressionType.NotEqual:
                    case ExpressionType.GreaterThan:
                    case ExpressionType.LessThan:
                    case ExpressionType.GreaterThanOrEqual:
                    case ExpressionType.LessThanOrEqual:
                        ComparisonExpression comparisonExpression = (ComparisonExpression) expression;
                        foreach (IExpression<float> exp in comparisonExpression.Expressions)
                        {
                            XElement elm = new XElement(exp.ExpressionType.ToString());
                            stack.Push(expression, elm);
                            element.Add(elm);
                        }
                        break;
                    case ExpressionType.And:
                    case ExpressionType.Or:
                    case ExpressionType.BoolEqual:
                    case ExpressionType.Xor:
                    case ExpressionType.Not:
                        LogicalExpression logicalExpression = (LogicalExpression) expression;
                        foreach (IExpression<bool> exp in logicalExpression.Expressions)
                        {
                            XElement elm = new XElement(exp.ExpressionType.ToString());
                            stack.Push(expression, elm);
                            element.Add(elm);
                        }
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            return rootElement;
        }
开发者ID:billings7,项目名称:EscherTilier,代码行数:76,代码来源:FileStorage.cs


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