Пример #1
0
        public void C8_10_3_A_CreatingPersistentData()
        {
            OptionData od = new OptionData()
            {
                ID   = "Test1",
                r    = 0.05,
                sig  = 0.20,
                K    = 100,
                T    = 365,
                b    = 0.01,
                otyp = "Call"
            };

            using (var backingStore = new MemoryStream())
            {
                var bw = new BinaryWriter(backingStore);
                od.SaveData(bw);

                backingStore.Position = 0;

                //Change some variables
                od.r = 0.1;

                var br = new BinaryReader(backingStore);
                od.ReadData(br);
            }

            Assert.AreEqual(od.r, 0.05);
        }
 public static void ReadData(this OptionData option, BinaryReader br)
 {
     option.r    = br.ReadDouble();
     option.sig  = br.ReadDouble();
     option.K    = br.ReadDouble();
     option.T    = br.ReadDouble();
     option.b    = br.ReadDouble();
     option.otyp = br.ReadString();
 }
        public static void SaveData(this OptionData option, BinaryWriter bw)
        {
            bw.Write(option.r);
            bw.Write(option.sig);
            bw.Write(option.K);
            bw.Write(option.T);
            bw.Write(option.b);
            bw.Write(option.otyp);

            bw.Flush();     // clear BinaryWriter buffer
        }