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


C# CType.getPredefType方法代码示例

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


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

示例1: WhichConversionIsBetter

        public BetterType WhichConversionIsBetter(CType argType,
            CType p1, CType p2)
        {
            // 7.4.2.4 Better conversion from type
            //
            // Given a conversion C1 that converts from a type S to a type T1 and a conversion C2
            // that converts from a type S to a type T2, the better conversion of the two conversions
            // is determined as follows:
            //* If T1 and T2 are the same type, neither conversion is better
            //* If S is T1, C1 is the better conversion.
            //* If S is T2, C2 is the better conversion.
            //* If an implicit conversion from T1 to T2 exists and no implicit conversion from T2 to
            //   T1 exists, C1 is the better conversion.
            //* If an implicit conversion from T2 to T1 exists and no implicit conversion from T1 to
            //   T2 exists, C2 is the better conversion.
            //
            // [Otherwise, see table above for better integral type conversions.]

            if (p1 == p2)
            {
                return BetterType.Same;
            }

            if (argType == p1)
            {
                return BetterType.Left;
            }

            if (argType == p2)
            {
                return BetterType.Right;
            }

            bool a2b = canConvert(p1, p2);
            bool b2a = canConvert(p2, p1);

            if (a2b && !b2a)
            {
                return BetterType.Left;
            }
            if (b2a && !a2b)
            {
                return BetterType.Right;
            }

            Debug.Assert(b2a == a2b);

            if (p1.isPredefined() && p2.isPredefined() &&
                p1.getPredefType() <= PredefinedType.PT_OBJECT && p2.getPredefType() <= PredefinedType.PT_OBJECT)
            {
                int c = s_betterConversionTable[(int)p1.getPredefType()][(int)p2.getPredefType()];
                if (c == 1)
                {
                    return BetterType.Left;
                }
                else if (c == 2)
                {
                    return BetterType.Right;
                }
            }

            return BetterType.Neither;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:63,代码来源:Better.cs


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