ReadContentsAsObject() public method

Reads the contents of the current data value.
/// /// The value of equals false, or /// One of the ReadContents methods has already been called for the current data value. /// /// has been called.
public ReadContentsAsObject ( ) : object
return object
Example #1
0
        private static void AssertDecode(int expectedInnerNumber, Action <EmberReader> assertEqual, params byte[] input)
        {
            using (var stream = new MemoryStream(input))
                using (var reader = new EmberReader(stream, 1))
                {
                    AssertThrow <InvalidOperationException>(() => reader.InnerNumber.GetHashCode().Ignore());
                    AssertThrow <InvalidOperationException>(() => reader.OuterId.Ignore());
                    AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject());
                    Assert.IsFalse(reader.CanReadContents);
                    Assert.IsTrue(reader.Read());
                    Assert.AreEqual(EmberId.CreateApplication(0), reader.OuterId);
                    Assert.AreEqual(expectedInnerNumber, reader.InnerNumber);
                    assertEqual(reader);
                    AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject());
                    Assert.IsFalse(reader.Read());

                    reader.Dispose();
                    Assert.IsFalse(reader.CanReadContents);
                    AssertThrow <ObjectDisposedException>(() => reader.InnerNumber.Ignore());
                    AssertThrow <ObjectDisposedException>(() => reader.OuterId.Ignore());
                    AssertThrow <ObjectDisposedException>(() => reader.ReadContentsAsObject());
                }

            using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings()
            {
                Indent = true
            }))
            {
                new EmberConverter(GlowTypes.Instance).ToXml(input, writer);
                Console.WriteLine();
                Console.WriteLine();
            }
        }
Example #2
0
        private static void ReadAll(params byte[] input)
        {
            using (var stream = new MemoryStream(input))
                using (var reader = new EmberReader(stream, 1))
                {
                    while (reader.Read())
                    {
                        switch (reader.InnerNumber)
                        {
                        case InnerNumber.EndContainer:
                            AssertThrow <InvalidOperationException>(() => reader.OuterId.Ignore());
                            Assert.IsFalse(reader.CanReadContents);
                            AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject());
                            break;

                        case InnerNumber.Sequence:
                        case InnerNumber.Set:
                            reader.OuterId.Ignore();
                            Assert.IsFalse(reader.CanReadContents);
                            AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject());
                            break;

                        case InnerNumber.Boolean:
                        case InnerNumber.Integer:
                        case InnerNumber.Octetstring:
                        case InnerNumber.Real:
                        case InnerNumber.Utf8String:
                        case InnerNumber.RelativeObjectIdentifier:
                            reader.OuterId.Ignore();
                            Assert.IsTrue(reader.CanReadContents);
                            reader.ReadContentsAsObject();
                            break;

                        default:
                            Assert.IsTrue(reader.InnerNumber >= InnerNumber.FirstApplication);
                            reader.OuterId.Ignore();
                            Assert.IsFalse(reader.CanReadContents);
                            AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject());
                            break;
                        }
                    }
                }
        }