Lawo.EmberPlusSharp.Ember.EmberReader.ReadContentsAsBoolean C# (CSharp) Méthode

ReadContentsAsBoolean() public méthode

Reads the contents of the current data value as a bool.
An error occurred while parsing the EmBER-encoded data, see /// for more information. /// /// The value of is not equal to , /// or /// The contents of the current data value has already been read. /// /// has been called.
public ReadContentsAsBoolean ( ) : bool
Résultat bool
        public bool ReadContentsAsBoolean()
        {
            this.AssertCanReadContents(Ember.InnerNumber.Boolean);
            return Read8Bit(this.readBuffer, this.ContentsLength.GetValueOrDefault(), false) != 0;
        }

Usage Example

Exemple #1
0
        public void SkipContentsTest()
        {
            using (var stream = new MemoryStream(new byte[] { 0x60, 0x03, 0x01, 0x01, 0xFF, 0x60, 0x03, 0x01, 0x01, 0x00 }))
                using (var reader = new EmberReader(stream, 1))
                {
                    Assert.IsTrue(reader.Read());
                    Assert.IsTrue(reader.Read());
                    Assert.IsFalse(reader.ReadContentsAsBoolean());
                }

            var original = new byte[64];

            this.Random.NextBytes(original);
            byte[] encoded;

            using (var stream = new MemoryStream())
            {
                using (var writer = new EmberWriter(stream))
                {
                    writer.WriteValue(EmberId.CreateApplication(0), original);
                    writer.WriteValue(EmberId.CreateApplication(1), true);
                }

                encoded = stream.ToArray();
            }

            using (var stream = new MemoryStream(encoded))
                using (var reader = new EmberReader(stream, 1))
                {
                    Assert.IsTrue(reader.Read());
                    Assert.AreEqual(InnerNumber.Octetstring, reader.InnerNumber);
                    Assert.IsTrue(reader.Read());
                    Assert.AreEqual(InnerNumber.Boolean, reader.InnerNumber);
                    Assert.AreEqual(true, reader.ReadContentsAsBoolean());
                    Assert.IsFalse(reader.Read());
                }
        }
All Usage Examples Of Lawo.EmberPlusSharp.Ember.EmberReader::ReadContentsAsBoolean