BinaryDataExtensions Create Method Delta Engine Documentation
Loads a binary data object and reconstructs the object based on the saved type information. View code on GitHub

Namespace: DeltaEngine.Core
Assembly: DeltaEngine (in DeltaEngine.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public static Object Create(
	this BinaryReader reader
)

Return Value

Type: Object

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type BinaryReader. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks

Tests: DeltaEngine.Tests.Core.BinaryDataExtensionsTests
Examples

3 unit tests call DeltaEngine.Core.BinaryDataExtensions.Create(System.IO.BinaryReader)
[Test]
public void DynamicallyCreatedTypeIsNotStored()
{
    var unknownObject = new ExpandoObject();
    Assert.Throws<BinaryDataExtensions.NoShortNameStoredFor>(
        () => BinaryDataExtensions.GetShortName(unknownObject));
}
[Test]
public void ThereMustBeSomeDataToReadInStream()
{
    var binaryReader = new BinaryReader(new MemoryStream());
    Assert.Throws<BinaryDataExtensions.NotEnoughDataLeftInStream>(() => binaryReader.Create());
}
[Test]
public void ExpectExceptionForUnreadableData()
{
    var message = new TestMessage { content = "This message cannot be resolved!", ID = 0 };
    var memoryStream = new MemoryStream(new byte[64]);
    var binaryWriter = new BinaryWriter(memoryStream);
    binaryWriter.Write(BinaryDataExtensions.ToByteArray(message));
    memoryStream.Position = 0;
    var binaryReader = new BinaryReader(memoryStream);
    Assert.Throws<TypeLoadException>(() => binaryReader.Create());
}
See Also