System.Xml.Xsl.IlGen.XmlILOptimizerVisitor.FoldXsltConvert C# (CSharp) Method

FoldXsltConvert() private method

Fold a XsltConvert applied to a Literal into another Literal. If the fold results in some kind of conversion error, or if the QilExpression cannot represent the result as a Literal, return an unfolded XsltConvert expression.
private FoldXsltConvert ( QilNode ndLiteral, XmlQueryType typTarget ) : QilNode
ndLiteral QilNode
typTarget XmlQueryType
return QilNode
        private QilNode FoldXsltConvert(QilNode ndLiteral, XmlQueryType typTarget) {
            try {
                if (typTarget.IsAtomicValue) {
                    // Convert the literal to an XmlAtomicValue
                    XmlAtomicValue value = new XmlAtomicValue(ndLiteral.XmlType.SchemaType, ExtractLiteralValue(ndLiteral));
                    value = XsltConvert.ConvertToType(value, typTarget);

                    if (typTarget == TypeFactory.StringX)
                        return this.f.LiteralString(value.Value);
                    else if (typTarget == TypeFactory.IntX)
                        return this.f.LiteralInt32(value.ValueAsInt);
                    else if (typTarget == TypeFactory.IntegerX)
                        return this.f.LiteralInt64(value.ValueAsLong);
                    else if (typTarget == TypeFactory.DecimalX)
                        return this.f.LiteralDecimal((decimal) value.ValueAs(XsltConvert.DecimalType));
                    else if (typTarget == TypeFactory.DoubleX)
                        return this.f.LiteralDouble(value.ValueAsDouble);
                    else if (typTarget == TypeFactory.BooleanX)
                        return value.ValueAsBoolean ? this.f.True() : this.f.False();
                }
            }
            catch (OverflowException) {}
            catch (FormatException) {}

            // Conversion error or QilExpression cannot represent resulting literal
            return this.f.XsltConvert(ndLiteral, typTarget);
        }
XmlILOptimizerVisitor