Example #1
0
        /// <summary>
        /// Parses a property list from a byte array.
        /// </summary>
        /// <param name="bytes">The property list data as a byte array.</param>
        /// <returns>The root object in the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
        public static NSObject Parse(byte[] bytes)
        {
            switch (DetermineType(bytes))
            {
            case TYPE_BINARY:
                return(BinaryPropertyListParser.Parse(bytes));

            case TYPE_XML:
                return(XmlPropertyListParser.Parse(bytes));

            case TYPE_ASCII:
                return(ASCIIPropertyListParser.Parse(bytes));

            default:
                throw new PropertyListFormatException("The given data is not a property list of a supported format.");
            }
        }
Example #2
0
        /// <summary>
        /// Parses integers and real numbers from their binary representation.
        /// <i>Note: real numbers are not yet supported.</i>
        /// </summary>
        /// <param name="bytes">The binary representation</param>
        /// <param name="type">The type of number</param>
        /// <seealso cref="INTEGER"/>
        /// <seealso cref="REAL"/>
        public NSNumber(byte[] bytes, int type)
        {
            switch (type)
            {
            case INTEGER:
                doubleValue = longValue = BinaryPropertyListParser.ParseLong(bytes);
                break;

            case REAL:
                doubleValue = BinaryPropertyListParser.ParseDouble(bytes);
                longValue   = (long)Math.Round(doubleValue);
                break;

            default:
                throw new ArgumentException("Type argument is not valid.");
            }
            this.type = type;
        }
Example #3
0
        /// <summary>
        /// Parses a property list from a file.
        /// </summary>
        /// <param name="f">The property list file.</param>
        /// <returns>The root object in the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
        public static NSObject Parse(FileInfo f)
        {
            int type;

            using (FileStream fis = f.OpenRead()) {
                type = DetermineType(fis);
            }

            switch (type)
            {
            case TYPE_BINARY:
                return(BinaryPropertyListParser.Parse(f));

            case TYPE_XML:
                return(XmlPropertyListParser.Parse(f));

            case TYPE_ASCII:
                return(ASCIIPropertyListParser.Parse(f));

            default:
                throw new PropertyListFormatException("The given file is not a property list of a supported format.");
            }
        }
Example #4
0
        /// <summary>
        /// Parses a binary property list from a byte array.
        /// </summary>
        /// <param name="data">The binary property list's data.</param>
        /// <returns>The root object of the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
        /// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
        public static NSObject Parse(byte[] data)
        {
            BinaryPropertyListParser parser = new BinaryPropertyListParser();

            return(parser.DoParse(data));
        }
Example #5
0
 /// <summary>
 /// Creates a date from its binary representation.
 /// </summary>
 /// <param name="bytes">bytes The date bytes</param>
 public NSDate(byte[] bytes)
 {
     //dates are 8 byte big-endian double, seconds since the epoch
     date = EPOCH.AddSeconds(BinaryPropertyListParser.ParseDouble(bytes));
 }