コード例 #1
0
        public IImportable Import()
        {
            Stream s = null;

            try
            {
                using (s = File.Open(_setting.FullPath, FileMode.Open))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    byte[]          bytes     = (byte[])formatter.Deserialize(s);
                    _data = BinaryIO.FromBytes <object>(bytes);
                }
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            return(this);
        }
コード例 #2
0
ファイル: RepositoryTests.cs プロジェクト: peeyalk/Sin.Net
        public void ExportRepositoryToByteArray()
        {
            // arrange
            var input = new TestRepository {
                MyProperty = "hello test"
            };

            // act
            var bytes  = BinaryIO.ToBytes(input);
            var result = BinaryIO.FromBytes <TestRepository>(bytes);

            // assert
            Assert.AreEqual(result.MyProperty, input.MyProperty);
        }