public Property(string name, string type) { this.Name = name; this.DataType = GetType(type); }
/// <summary> /// Reads bytes depending on gines parameter /// </summary> /// <param name="type"></param> /// <returns></returns> private float ReadType(StanfordPly.PropertyType type) { byte[] bytes; switch (type) { case StanfordPly.PropertyType.CHAR: bytes = reader.ReadBytes(1); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return(BitConverter.ToChar(bytes, 0)); case StanfordPly.PropertyType.UCHAR: bytes = reader.ReadBytes(1); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return((float)bytes[0]); case StanfordPly.PropertyType.SHORT: bytes = reader.ReadBytes(2); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return(BitConverter.ToInt16(bytes, 0)); case StanfordPly.PropertyType.USHORT: bytes = reader.ReadBytes(2); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return(BitConverter.ToUInt16(bytes, 0)); case StanfordPly.PropertyType.INT: bytes = reader.ReadBytes(4); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return(BitConverter.ToInt32(bytes, 0)); case StanfordPly.PropertyType.UINT: bytes = reader.ReadBytes(4); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return(BitConverter.ToUInt32(bytes, 0)); case StanfordPly.PropertyType.FLOAT: bytes = reader.ReadBytes(4); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return((float)BitConverter.ToSingle(bytes, 0)); case StanfordPly.PropertyType.DOUBLE: bytes = reader.ReadBytes(8); if (format == StanfordPly.Format.BINARY_BE) { Array.Reverse(bytes); } return((float)BitConverter.ToDouble(bytes, 0)); default: throw new IOException("Invalid data type"); } }