Example #1
0
        /// <summary>
        /// 暗黙のキャストを探す。
        /// </summary>
        private DynamicMetaObject DefferentType(DynamicMetaObject left, DynamicMetaObject right)
        {
            var val = TryCalcNumeric(left, right);

            if (val != null)
            {
                return(val);
            }
            // 左辺のキャスト
            var mInfo = BinderHelper.GetImplicitCast(left.LimitType, right.LimitType);

            if (mInfo != null)
            {
                Expression expr = Expression.MakeBinary(this.Operation,
                                                        BinderHelper.Wrap(left.Expression, left.LimitType, right.LimitType),
                                                        Expression.Convert(right.Expression, right.LimitType));
                return(new DynamicMetaObject(
                           BinderHelper.Wrap(expr, this.ReturnType),
                           BinderHelper.GetTypeRestriction(left, right)));
            }
            // 右辺のキャスト
            mInfo = BinderHelper.GetImplicitCast(right.LimitType, left.LimitType);
            if (mInfo != null)
            {
                Expression expr = Expression.MakeBinary(this.Operation,
                                                        Expression.Convert(left.Expression, left.LimitType),
                                                        BinderHelper.Wrap(right.Expression, right.LimitType, left.LimitType));
                return(new DynamicMetaObject(
                           BinderHelper.Wrap(expr, this.ReturnType),
                           BinderHelper.GetTypeRestriction(left, right)));
            }
            return(BinderHelper.NoResult(_name, this.ReturnType, left, right));
        }
Example #2
0
 /// <summary>
 /// 比較方法を検索し、見つからなかったら例外を投げるMetaObjectを返す。
 /// </summary>
 private DynamicMetaObject Search(DynamicMetaObject left, DynamicMetaObject right)
 {
     return
         (TryCalcDefferentNumberType(left, right) ??
          TryImplicitCast(left, right) ??
          TryUseIComparableT(left, right) ??
          BinderHelper.NoResult("比較", this.ReturnType, left, right));
 }