-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathCustomerModel.cs
66 lines (53 loc) · 1.66 KB
/
CustomerModel.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using PostSharp.Patterns.Collections;
using PostSharp.Patterns.Contracts;
using PostSharp.Patterns.Model;
using PostSharp.Patterns.Threading;
using System.IO;
using System.Threading;
namespace PostSharp.Samples.Xaml
{
public class CustomerModel : ModelBase
{
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public string Phone { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }
[Child]
public AdvisableCollection<AddressModel> Addresses { get; set; }
[Reference]
public AddressModel PrincipalAddress { get; set; }
[Reader]
public void Save(string path)
{
using (var stringWriter = new StreamWriter(path))
{
// We need to make sure the object graph is not being modified when we save,
// and this is ensured by [ReaderWriterSynchronized] in ModelBase.
stringWriter.WriteLine($"FirstName: {FirstName}");
Thread.Sleep(1000);
stringWriter.WriteLine($"LastName: {LastName}");
Thread.Sleep(1000);
stringWriter.WriteLine($"Phone: {Phone}");
Thread.Sleep(1000);
stringWriter.WriteLine($"Mobile: {Mobile}");
Thread.Sleep(1000);
stringWriter.WriteLine($"Email: {Email}");
Thread.Sleep(1000);
foreach (var address in Addresses)
{
Thread.Sleep(1000);
if (address == PrincipalAddress)
{
stringWriter.WriteLine($"Principal address: {address}");
}
else
{
stringWriter.WriteLine($"Secondary address: {address}");
}
}
}
}
}
}