/// <summary> /// Interprets the raw data stored in the <see cref="Data"/> property as a literal. /// </summary> /// <param name="elementType">The type of the literal.</param> /// <returns>The deserialized literal.</returns> public object InterpretData(ElementType elementType) { var reader = new ByteArrayReader(Data); return(elementType switch { ElementType.Boolean => (object)(reader.ReadByte() != 0), ElementType.Char => (char)reader.ReadUInt16(), ElementType.I1 => reader.ReadSByte(), ElementType.U1 => reader.ReadByte(), ElementType.I2 => reader.ReadInt16(), ElementType.U2 => reader.ReadUInt16(), ElementType.I4 => reader.ReadInt32(), ElementType.U4 => reader.ReadUInt32(), ElementType.I8 => reader.ReadInt64(), ElementType.U8 => reader.ReadUInt64(), ElementType.R4 => reader.ReadSingle(), ElementType.R8 => reader.ReadDouble(), ElementType.String => Encoding.Unicode.GetString(reader.ReadToEnd()), _ => throw new ArgumentOutOfRangeException(nameof(elementType)) });