public void success_convert() { var engineResult = new EngineResult { Title="Title", Url = "Url", ItemHtml="<b>Html</b>" }; var bytes = engineResult.ToBinary(); AssertEx.PropertyValuesAreEquals(engineResult,EngineResult.TryGetFromBinary(bytes)); }
public static KeywordResult TryGetFromBinary(byte[] data) { using (var mem = new MemoryStream(data)) using (var bin = new BinaryReader(mem)) { var result = new KeywordResult { Keyword = bin.ReadString(), Date = DateTime.FromBinary(bin.ReadInt64()), Engine = (Engine)bin.ReadInt32(), Version = bin.ReadString(), EngineResults = new List<EngineResult>() }; var count = bin.ReadInt32(); for (int i = 0; i < count; i++) { EngineResult engineResult = new EngineResult { Title = bin.ReadString(), Url = bin.ReadString(), ItemHtml = bin.ReadString() }; result.EngineResults.Add(engineResult); } return result; } }