#region PDFsharp - A .NET library for processing PDF // // Authors: // Stefan Lange // // Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany) // // http://www.pdfsharp.com // http://sourceforge.net/projects/pdfsharp // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #endregion using System; using System.Diagnostics; using System.Globalization; using PdfSharp.Pdf.IO; namespace PdfSharp.Pdf { /// /// Represents a direct unsigned integer value. /// [DebuggerDisplay("({Value})")] public sealed class PdfUInteger : PdfNumber, IConvertible { /// /// Initializes a new instance of the class. /// public PdfUInteger() { } /// /// Initializes a new instance of the class. /// public PdfUInteger(uint value) { _value = value; } /// /// Gets the value as integer. /// public uint Value { // This class must behave like a value type. Therefore it cannot be changed (like System.String). get { return _value; } } readonly uint _value; /// /// Returns the unsigned integer as string. /// public override string ToString() { // ToString is impure but does not change the value of _value. // ReSharper disable ImpureMethodCallOnReadonlyValueField return _value.ToString(CultureInfo.InvariantCulture); // ReSharper restore ImpureMethodCallOnReadonlyValueField } /// /// Writes the integer as string. /// internal override void WriteObject(PdfWriter writer) { writer.Write(this); } #region IConvertible Members /// /// Converts the value of this instance to an equivalent 64-bit unsigned integer. /// public ulong ToUInt64(IFormatProvider provider) { return Convert.ToUInt64(_value); } /// /// Converts the value of this instance to an equivalent 8-bit signed integer. /// public sbyte ToSByte(IFormatProvider provider) { throw new InvalidCastException(); } /// /// Converts the value of this instance to an equivalent double-precision floating-point number. /// public double ToDouble(IFormatProvider provider) { return _value; } /// /// Returns an undefined DateTime structure. /// public DateTime ToDateTime(IFormatProvider provider) { // TODO: Add PdfUInteger.ToDateTime implementation return new DateTime(); } /// /// Converts the value of this instance to an equivalent single-precision floating-point number. /// public float ToSingle(IFormatProvider provider) { return _value; } /// /// Converts the value of this instance to an equivalent Boolean value. /// public bool ToBoolean(IFormatProvider provider) { return Convert.ToBoolean(_value); } /// /// Converts the value of this instance to an equivalent 32-bit signed integer. /// public int ToInt32(IFormatProvider provider) { return Convert.ToInt32(_value); } /// /// Converts the value of this instance to an equivalent 16-bit unsigned integer. /// public ushort ToUInt16(IFormatProvider provider) { return Convert.ToUInt16(_value); } /// /// Converts the value of this instance to an equivalent 16-bit signed integer. /// public short ToInt16(IFormatProvider provider) { return Convert.ToInt16(_value); } /// /// Converts the value of this instance to an equivalent . /// string IConvertible.ToString(IFormatProvider provider) { return _value.ToString(provider); } /// /// Converts the value of this instance to an equivalent 8-bit unsigned integer. /// public byte ToByte(IFormatProvider provider) { return Convert.ToByte(_value); } /// /// Converts the value of this instance to an equivalent Unicode character. /// public char ToChar(IFormatProvider provider) { return Convert.ToChar(_value); } /// /// Converts the value of this instance to an equivalent 64-bit signed integer. /// public long ToInt64(IFormatProvider provider) { return _value; } /// /// Returns type code for 32-bit integers. /// public TypeCode GetTypeCode() { return TypeCode.Int32; } /// /// Converts the value of this instance to an equivalent number. /// public decimal ToDecimal(IFormatProvider provider) { return _value; } /// /// Returns null. /// public object ToType(Type conversionType, IFormatProvider provider) { // TODO: Add PdfUInteger.ToType implementation return null; } /// /// Converts the value of this instance to an equivalent 32-bit unsigned integer. /// public uint ToUInt32(IFormatProvider provider) { return Convert.ToUInt32(_value); } #endregion } }