示例#1
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable unsignedByte
        /// in the supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which the unsignedByte is to be extracted </param>
        /// <returns> New ResultSequence consisting of the 'unsignedByte' supplied </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            // the function conversion rules apply here too. Get the argument
            // and convert it's string value to a unsignedByte.
            Item aat = arg.first();

            try
            {
                System.Numerics.BigInteger.TryParse(aat.StringValue, out System.Numerics.BigInteger bigInt);

                // doing the range checking
                // min value is 0
                // max value is 255
                System.Numerics.BigInteger min = new System.Numerics.BigInteger(0);
                System.Numerics.BigInteger max = new System.Numerics.BigInteger(255L);

                if (bigInt.CompareTo(min) < 0 || bigInt.CompareTo(max) > 0)
                {
                    // invalid input
                    throw DynamicError.cant_cast(null);
                }

                return(new XSUnsignedByte(bigInt));
            }
            catch (System.FormatException)
            {
                throw DynamicError.cant_cast(null);
            }
        }
示例#2
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable long in the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which the long is to be extracted </param>
        /// <returns> New ResultSequence consisting of the 'long' supplied </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            // the function conversion rules apply here too. Get the argument
            // and convert it's string value to a long.
            Item aat = arg.first();

            try
            {
                System.Numerics.BigInteger.TryParse(aat.StringValue, out System.Numerics.BigInteger bigInt);

                // doing the range checking
                System.Numerics.BigInteger min = new System.Numerics.BigInteger(-9223372036854775808L);
                System.Numerics.BigInteger max = new System.Numerics.BigInteger(9223372036854775807L);

                if (bigInt.CompareTo(min) < 0 || bigInt.CompareTo(max) > 0)
                {
                    // invalid input
                    DynamicError.throw_type_error();
                }

                return(new XSLong(bigInt));
            }
            catch (System.FormatException)
            {
                throw DynamicError.cant_cast(null);
            }
        }