CheckXsltValue() private method

private CheckXsltValue ( IList val ) : void
val IList
return void
Beispiel #1
0
        public static double ToDouble(XPathItem item)
        {
            XsltLibrary.CheckXsltValue(item);

            if (item.IsNode)
            {
                return(XPathConvert.StringToDouble(item.Value));
            }

            Type itemType = item.ValueType;

            if (itemType == StringType)
            {
                return(XPathConvert.StringToDouble(item.Value));
            }
            else if (itemType == DoubleType)
            {
                return(item.ValueAsDouble);
            }
            else
            {
                Debug.Assert(itemType == BooleanType, $"Unexpected type of atomic sequence {itemType}");
                return(item.ValueAsBoolean ? 1d : 0d);
            }
        }
Beispiel #2
0
        //------------------------------------------------------------------------
        // ToBoolean (internal type to internal type)
        //------------------------------------------------------------------------

        public static bool ToBoolean(XPathItem item)
        {
            XsltLibrary.CheckXsltValue(item);

            if (item.IsNode)
            {
                return(true);
            }

            Type itemType = item.ValueType;

            if (itemType == StringType)
            {
                return(item.Value.Length != 0);
            }
            else if (itemType == DoubleType)
            {
                // (x < 0 || 0 < x)  ==  (x != 0) && !Double.IsNaN(x)
                double dbl = item.ValueAsDouble;
                return(dbl < 0 || 0 < dbl);
            }
            else
            {
                Debug.Assert(itemType == BooleanType, $"Unexpected type of atomic sequence {itemType}");
                return(item.ValueAsBoolean);
            }
        }
Beispiel #3
0
        public static bool ToBoolean(IList <XPathItem> listItems)
        {
            XsltLibrary.CheckXsltValue(listItems);

            if (listItems.Count == 0)
            {
                return(false);
            }

            return(ToBoolean(listItems[0]));
        }
Beispiel #4
0
        public static string ToString(IList <XPathItem> listItems)
        {
            XsltLibrary.CheckXsltValue(listItems);

            if (listItems.Count == 0)
            {
                return(string.Empty);
            }

            return(ToString(listItems[0]));
        }
Beispiel #5
0
        public static IList <XPathNavigator> ToNodeSet(IList <XPathItem> listItems)
        {
            XsltLibrary.CheckXsltValue(listItems);

            if (listItems.Count == 1)
            {
                return(new XmlQueryNodeSequence(ToNode(listItems[0])));
            }

            return(XmlILStorageConverter.ItemsToNavigators(listItems));
        }
Beispiel #6
0
        public static XPathNavigator ToNode(IList <XPathItem> listItems)
        {
            XsltLibrary.CheckXsltValue(listItems);

            if (listItems.Count == 1)
            {
                return(ToNode(listItems[0]));
            }

            throw new XslTransformException(SR.Xslt_NodeSetNotNode, string.Empty);
        }
Beispiel #7
0
        public static double ToDouble(IList <XPathItem> listItems)
        {
            XsltLibrary.CheckXsltValue(listItems);

            if (listItems.Count == 0)
            {
                return(double.NaN);
            }

            return(ToDouble(listItems[0]));
        }
Beispiel #8
0
        public static string ToString(XPathItem item)
        {
            XsltLibrary.CheckXsltValue(item);

            // Use XPath 1.0 rules to convert double to string
            if (!item.IsNode && item.ValueType == DoubleType)
            {
                return(XPathConvert.DoubleToString(item.ValueAsDouble));
            }

            return(item.Value);
        }
Beispiel #9
0
        //------------------------------------------------
        // Msxml Extension Functions
        //------------------------------------------------

        public static double MSNumber(IList <XPathItem> value)
        {
            XsltLibrary.CheckXsltValue(value);
            if (value.Count == 0)
            {
                return(Double.NaN);
            }
            XPathItem item = value[0];

            string stringValue;

            if (item.IsNode)
            {
                stringValue = item.Value;
            }
            else
            {
                Type itemType = item.ValueType;
                if (itemType == XsltConvert.StringType)
                {
                    stringValue = item.Value;
                }
                else if (itemType == XsltConvert.DoubleType)
                {
                    return(item.ValueAsDouble);
                }
                else
                {
                    Debug.Assert(itemType == XsltConvert.BooleanType, "Unexpected type of atomic value " + itemType.ToString());
                    return(item.ValueAsBoolean ? 1d : 0d);
                }
            }

            Debug.Assert(stringValue != null);
            double d;

            if (XmlConvert.TryToDouble(stringValue, out d) != null)
            {
                d = double.NaN;
            }
            return(d);
        }
Beispiel #10
0
        //------------------------------------------------------------------------
        // EnsureXXX methods (TreatAs)
        //------------------------------------------------------------------------

        public static IList <XPathNavigator> EnsureNodeSet(IList <XPathItem> listItems)
        {
            XsltLibrary.CheckXsltValue(listItems);

            if (listItems.Count == 1)
            {
                XPathItem item = listItems[0];
                if (!item.IsNode)
                {
                    throw new XslTransformException(SR.XPath_NodeSetExpected, string.Empty);
                }

                if (item is RtfNavigator)
                {
                    throw new XslTransformException(SR.XPath_RtfInPathExpr, string.Empty);
                }
            }

            return(XmlILStorageConverter.ItemsToNavigators(listItems));
        }
Beispiel #11
0
        //------------------------------------------------
        // EXslt Functions
        //------------------------------------------------

        public static string EXslObjectType(IList <XPathItem> value)
        {
            if (value.Count != 1)
            {
                XsltLibrary.CheckXsltValue(value);
                return("node-set");
            }

            XPathItem item = value[0];

            if (item is RtfNavigator)
            {
                return("RTF");
            }
            else if (item.IsNode)
            {
                Debug.Assert(item is XPathNavigator);
                return("node-set");
            }

            object o = item.TypedValue;

            if (o is string)
            {
                return("string");
            }
            else if (o is double)
            {
                return("number");
            }
            else if (o is bool)
            {
                return("boolean");
            }
            else
            {
                Debug.Fail("Unexpected type: " + o.GetType().ToString());
                return("external");
            }
        }
Beispiel #12
0
        //------------------------------------------------------------------------
        // ToNode (internal type to internal type)
        //------------------------------------------------------------------------

        public static XPathNavigator ToNode(XPathItem item)
        {
            XsltLibrary.CheckXsltValue(item);

            if (!item.IsNode)
            {
                // Create Navigator over text node containing string value of item
                XPathDocument doc    = new XPathDocument();
                XmlRawWriter  writer = doc.LoadFromWriter(XPathDocument.LoadFlags.AtomizeNames, string.Empty);
                writer.WriteString(ToString(item));
                writer.Close();
                return(doc.CreateNavigator());
            }

            RtfNavigator?rtf = item as RtfNavigator;

            if (rtf != null)
            {
                return(rtf.ToNavigator());
            }

            return((XPathNavigator)item);
        }