Пример #1
0
            /// <summary>
            /// Converts the specified value to boolean.
            /// If the value does not exist, the function returns false.
            /// 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 bool GetBoolean(int index)
            {
                if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
                }

                object obj = this[index];

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

                PdfBoolean boolean = obj as PdfBoolean;

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

                PdfBooleanObject booleanObject = obj as PdfBooleanObject;

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

                throw new InvalidCastException("GetBoolean: Object is not a boolean.");
            }
Пример #2
0
 /// <summary>
 /// Writes the specified value to the PDF stream.
 /// </summary>
 public void Write(PdfBoolean value)
 {
   WriteSeparator(CharCat.Character);
   WriteRaw(value.Value ? "true" : "false");
   this.lastCat = CharCat.Character;
 }
Пример #3
0
 /// <summary>
 /// Sets the entry to a direct boolean value.
 /// </summary>
 public void SetBoolean(string key, bool value)
 {
   this[key] = new PdfBoolean(value);
 }
Пример #4
0
      /// <summary>
      /// Converts the specified value to boolean.
      /// If the value not exists, the function returns false.
      /// If the value is not convertible, the function throws an InvalidCastException.
      /// </summary>
      public bool GetBoolean(string key, bool create)
      {
        object obj = this[key];
        if (obj == null)
        {
          if (create)
            this[key] = new PdfBoolean();
          return false;
        }
        if (obj is PdfReference)
          obj = ((PdfReference)obj).Value;

        if (obj is PdfBoolean)
          return ((PdfBoolean)obj).Value;
        else if (obj is PdfBooleanObject)
          return ((PdfBooleanObject)obj).Value;
        throw new InvalidCastException("GetBoolean: Object is not a boolean.");
      }