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


C# Tuple.ContainsValue方法代码示例

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


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

示例1: Calculate

        /// <summary>
        /// </summary>
        public static Tuple Calculate(IPythonType startingType, Tuple bases, bool forceNewStyle)
        {
            if (bases.ContainsValue(startingType)) {
                throw Ops.TypeError("a __bases__ item causes an inheritance cycle");
            }

            List<IPythonType> mro = new List<IPythonType>();
            mro.Add(startingType);

            if (bases.Count != 0) {
                List<List<IPythonType>> mroList = new List<List<IPythonType>>();
                // build up the list - it contains the MRO of all our
                // bases as well as the bases themselves in the order in
                // which they appear.
                int oldSytleCount = 0;
                foreach (IPythonType type in bases) {
                    if (!(type is DynamicType))
                        oldSytleCount++;
                }

                foreach (IPythonType type in bases) {
                    DynamicType dt = type as DynamicType;
                    if (dt != null) {
                        mroList.Add(TupleToList(dt.MethodResolutionOrder));
                    } else if (oldSytleCount == 1 && !forceNewStyle) {
                        mroList.Add(GetOldStyleMro(type));
                    } else {
                        mroList.Add(GetNewStyleMro(type));
                    }
                }

                mroList.Add(TupleToList(bases));

                int lastRemove = -1;
                for (; ; ) {
                    bool removed = false, sawNonZero = false;
                    // now that we have our list, look for good heads
                    for (int i = 0; i < mroList.Count; i++) {
                        if (mroList[i].Count == 0) continue;    // we've removed everything from this list.

                        sawNonZero = true;
                        IPythonType head = mroList[i][0];
                        // see if we're in the tail of any other lists...
                        bool inTail = false;
                        for (int j = 0; j < mroList.Count; j++) {
                            if (mroList[j].Count != 0 && !mroList[j][0].Equals(head) && mroList[j].Contains(head)) {
                                inTail = true;
                                break;
                            }
                        }

                        if (!inTail) {
                            lastRemove = i;
                            if (mro.Contains(head)) {
                                throw Ops.TypeError("a __bases__ item causes an inheritance cycle");
                            }
                            // add it to the linearization, and remove
                            // it from our lists
                            mro.Add(head);

                            for (int j = 0; j < mroList.Count; j++) {
                                mroList[j].Remove(head);
                            }
                            removed = true;
                            break;
                        }
                    }

                    if (!sawNonZero) break;

                    if (!removed) {
                        // we've iterated through the list once w/o removing anything
                        throw Ops.TypeError("invalid order for base classes: {0} {1}",
                            mroList[0][0],
                            mroList[1][0]);
                    }
                }
            }

            return new Tuple(mro);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:83,代码来源:Mro.cs


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