System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.CreateCastExpression C# (CSharp) Method

CreateCastExpression() private method

private CreateCastExpression ( DbExpression source, Type toClrType, Type fromClrType ) : DbExpression
source DbExpression
toClrType Type
fromClrType Type
return DbExpression
        private DbExpression CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
        {
            // see if the source can be normalized as a set
            var setSource = NormalizeSetSource(source);
            if (!ReferenceEquals(source, setSource))
            {
                // if the resulting cast is a no-op (no either kind is supported
                // for set sources), yield the source
                if (null == GetCastTargetType(setSource.ResultType, toClrType, fromClrType, true))
                {
                    return source;
                }
            }

            // try to find the appropriate target target for the cast
            var toType = GetCastTargetType(source.ResultType, toClrType, fromClrType, true);
            if (null == toType)
            {
                // null indicates a no-op cast (from the perspective of the model)
                return source;
            }

            return source.CastTo(toType);
        }