forked from dotnet/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
52 lines (44 loc) · 1.56 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
// <Snippet3>
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
// </Snippet3>
namespace serialization
{
class Program
{
static void Main(string[] args)
{
// <Snippet4>
const string FileName = @"../../../SavedLoan.bin";
// </Snippet4>
// <Snippet1>
Loan TestLoan = new Loan(10000.0, 0.075, 36, "Neil Black");
// </Snippet1>
// <Snippet5>
if (File.Exists(FileName))
{
Console.WriteLine("Reading saved file");
Stream openFileStream = File.OpenRead(FileName);
BinaryFormatter deserializer = new BinaryFormatter();
TestLoan = (Loan)deserializer.Deserialize(openFileStream);
TestLoan.TimeLastLoaded = DateTime.Now;
openFileStream.Close();
}
// </Snippet5>
// <Snippet2>
TestLoan.PropertyChanged += (_, __) => Console.WriteLine($"New customer value: {TestLoan.Customer}");
TestLoan.Customer = "Henry Clay";
Console.WriteLine(TestLoan.InterestRate);
TestLoan.InterestRate = 7.1;
Console.WriteLine(TestLoan.InterestRate);
// </Snippet2>
// <Snippet6>
Stream SaveFileStream = File.Create(FileName);
BinaryFormatter serializer = new BinaryFormatter();
serializer.Serialize(SaveFileStream, TestLoan);
SaveFileStream.Close();
// </Snippet6>
}
}
}