Exemplo n.º 1
0
            /// <summary>
            /// Converts the specified value to integer.
            /// If the value does not exist, the function returns 0.
            /// If the value is not convertible, the function throws an InvalidCastException.
            /// If the index is out of range, the function throws an ArgumentOutOfRangeException.
            /// </summary>
            public int GetInteger(int index)
            {
                if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
                }

                object obj = this[index];

                if (obj == null)
                {
                    return(0);
                }

                PdfInteger integer = obj as PdfInteger;

                if (integer != null)
                {
                    return(integer.Value);
                }

                PdfIntegerObject integerObject = obj as PdfIntegerObject;

                if (integerObject != null)
                {
                    return(integerObject.Value);
                }

                throw new InvalidCastException("GetInteger: Object is not an integer.");
            }
Exemplo n.º 2
0
            /// <summary>
            /// Converts the specified value to double.
            /// If the value does not exist, the function returns 0.
            /// If the value is not convertible, the function throws an InvalidCastException.
            /// If the index is out of range, the function throws an ArgumentOutOfRangeException.
            /// </summary>
            public double GetReal(int index)
            {
                if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
                }

                object obj = this[index];

                if (obj == null)
                {
                    return(0);
                }

                PdfReal real = obj as PdfReal;

                if (real != null)
                {
                    return(real.Value);
                }

                PdfRealObject realObject = obj as PdfRealObject;

                if (realObject != null)
                {
                    return(realObject.Value);
                }

                PdfInteger integer = obj as PdfInteger;

                if (integer != null)
                {
                    return(integer.Value);
                }

                PdfIntegerObject integerObject = obj as PdfIntegerObject;

                if (integerObject != null)
                {
                    return(integerObject.Value);
                }

                throw new InvalidCastException("GetReal: Object is not a number.");
            }