8b88eb0d12e2c4dc2f930551d00ff40ec827a4af
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / View / VersionEditorViewModel.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Presentation.View
8 {
9     using System.Runtime;
10
11     internal class VersionEditorViewModel : ViewModel
12     {
13         private IVersionEditor editor;
14         private Version version;
15
16         public VersionEditorViewModel(IVersionEditor editor)
17         {
18             Fx.Assert(editor != null, "editor should not be null");
19             this.editor = editor;
20         }
21
22         public string VersionText
23         {
24             get
25             {
26                 if (this.version == null)
27                 {
28                     return null;
29                 }
30
31                 return this.version.ToString();
32             }
33
34             set
35             {
36                 if (this.VersionText != value)
37                 {
38                     if (string.IsNullOrEmpty(value))
39                     {
40                         this.Version = null;
41                         return;
42                     }
43
44                     Exception exception = null;
45
46                     try
47                     {
48                         this.Version = Version.Parse(value);
49                     }
50                     catch (ArgumentOutOfRangeException ex)
51                     {
52                         exception = ex;
53                     }
54                     catch (ArgumentException ex)
55                     {
56                         exception = ex;
57                     }
58                     catch (FormatException ex)
59                     {
60                         exception = ex;
61                     }
62                     catch (OverflowException ex)
63                     {
64                         exception = ex;
65                     }
66
67                     if (exception != null)
68                     {
69                         this.editor.ShowErrorMessage(exception.Message);
70
71                         // update UI to its old value
72                         this.NotifyPropertyChanged("VersionText");
73                     }
74                 }
75             }
76         }
77
78         public Version Version
79         {
80             get
81             {
82                 return this.version;
83             }
84
85             set
86             {
87                 if (this.version != value)
88                 {
89                     this.version = value;
90                     this.NotifyPropertyChanged("Version");
91                     this.NotifyPropertyChanged("VersionText");
92                 }
93             }
94         }
95     }
96 }