コード例 #1
0
ファイル: UserConversionCache.cs プロジェクト: zyj0021/Cyjb
            /// <summary>
            /// 更新最优的输入/输出类型。
            /// </summary>
            /// <param name="methodType">类型转换方法的输入/输出类型。</param>
            /// <param name="relation">实际输入类型与方法输入/输出类型间的关系。</param>
            /// <param name="relationJudge">方法输入/输出类型和最优类型间的关系判定。</param>
            /// <param name="bestType">当前的最优类型。</param>
            /// <param name="bestRelation">当前最优类型与实际输入/输出类型间的关系。</param>
            private void UpdateBestType(Type methodType, TypeRelation relation, bool relationJudge,
                                        ref Type bestType, ref TypeRelation bestRelation)
            {
                // 当前选择更差。
                if (relation > bestRelation)
                {
                    return;
                }
                // 当前选择更优,或者当前选择与最佳选择相同,但最佳选择没有类型填充。
                if (relation < bestRelation || bestType == null)
                {
                    bestType     = methodType;
                    bestRelation = relation;
                    bestMethod.Reset();
                    return;
                }
                ConversionType ctype = ConversionFactory.GetStandardConversion(methodType, bestType);

                if (ctype == ConversionType.None)
                {
                    // 找不到类型转换关系,令最佳选择前进至下一级别,并清除类型填充。
                    bestType = null;
                    bestRelation--;
                    bestMethod.Reset();
                    return;
                }
                if (ctype.IsImplicit() == relationJudge)
                {
                    // 当前选择被最优选择包含。
                    if (bestRelation == TypeRelation.Second)
                    {
                        bestType = methodType;
                        bestMethod.Reset();
                    }
                }
                else if (bestRelation == TypeRelation.Thirt)
                {
                    // 当前选择包含最优选择。
                    bestType = methodType;
                    bestMethod.Reset();
                }
            }