コード例 #1
0
        private MemberAssignment BindProperty(PropertyInfo prop, Expression exp)
        {
            var targetType = prop.PropertyType;

            if (targetType.GetNoneNullableType().IsValueType)
            {
                var type = TypeImplicitConvert.StandardImplicit(targetType, exp.Type);
                if (type != null && targetType != type)
                {
                    exp = Expression.Convert(exp, type);
                }
            }
            return(Expression.Bind(prop, exp));
        }
コード例 #2
0
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="left">左表达式结果</param>
        /// <param name="right">右表达式结果</param>
        private void ImplicitConvert(ref ReadResult left, ref ReadResult right)
        {
            if (left.Expression.Type != right.Expression.Type)
            {
                var type = TypeImplicitConvert.StandardImplicit(left.Expression.Type, right.Expression.Type);
                if (type != null)
                {
                    if (left.Expression.Type != type)
                    {
                        left.Expression = Expression.Convert(left.Expression, type);
                    }

                    if (right.Expression.Type != type)
                    {
                        right.Expression = Expression.Convert(right.Expression, type);
                    }
                }
            }
        }