Esempio n. 1
0
            /// <summary>
            /// Converts the specified value to double?.
            /// If the value does not exist, the function returns null.
            /// 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?GetNullableReal(int index)
            {
                if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
                }

                object obj = this[index];

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

                PdfNull @null = obj as PdfNull;

                if (@null != null)
                {
                    return(null);
                }

                PdfNullObject nullObject = obj as PdfNullObject;

                if (nullObject != null)
                {
                    return(null);
                }

                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.");
            }
Esempio n. 2
0
 /// <summary>
 /// Writes the specified value to the PDF stream.
 /// </summary>
 public void Write(PdfReal value)
 {
   WriteSeparator(CharCat.Character);
   WriteRaw(value.Value.ToString("0.###", CultureInfo.InvariantCulture));
   this.lastCat = CharCat.Character;
 }
Esempio n. 3
0
 /// <summary>
 /// Sets the entry to a direct double value.
 /// </summary>
 public void SetReal(string key, double value)
 {
   this[key] = new PdfReal(value);
 }
Esempio n. 4
0
      /// <summary>
      /// Converts the specified value to double.
      /// If the value not exists, the function returns 0.
      /// If the value is not convertible, the function throws an InvalidCastException.
      /// </summary>
      public double GetReal(string key, bool create)
      {
        object obj = this[key];
        if (obj == null)
        {
          if (create)
            this[key] = new PdfReal();
          return 0;
        }
        if (obj is PdfReference)
          obj = ((PdfReference)obj).Value;

        if (obj is PdfReal)
          return ((PdfReal)obj).Value;
        else if (obj is PdfRealObject)
          return ((PdfRealObject)obj).Value;
        else if (obj is PdfInteger)
          return ((PdfInteger)obj).Value;
        else if (obj is PdfIntegerObject)
          return ((PdfIntegerObject)obj).Value;
        throw new InvalidCastException("GetReal: Object is not a number.");
      }