HamBook – Blame information for rev 37

Subversion Repositories:
Rev:
Rev Author Line No. Line
37 office 1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7  
8 namespace HamBook.Radios.Generic
9 {
10 public class SplitState
11 {
12 public int State { get; set; }
13  
14 public SplitState(string state) : this()
15 {
16 State = Parse(state);
17 }
18  
19 public SplitState(int state) : this()
20 {
21 State = Parse(state);
22 }
23  
24 public SplitState()
25 {
26  
27 }
28  
29 public static bool TryParse(string state, out SplitState splitState)
30 {
31 switch (state)
32 {
33  
34 case "On":
35 case "Off":
36 case "+5kHz":
37 splitState = new SplitState(state);
38 return true;
39 default:
40 splitState = null;
41 return false;
42 }
43 }
44  
45 public static bool TryParse(int state, out SplitState splitState)
46 {
47 switch (state)
48 {
49 case 0:
50 case 1:
51 case 2:
52 splitState = new SplitState(state);
53 return true;
54 default:
55 splitState = null;
56 return false;
57 }
58 }
59  
60 private int Parse(string state)
61 {
62 switch (state)
63 {
64 case "Off":
65 return 0;
66 case "On":
67 return 1;
68 case "+5kHz":
69 return 2;
70 default:
71 throw new ArgumentException();
72 }
73 }
74  
75 private int Parse(int state)
76 {
77 switch (state)
78 {
79 case 0:
80 case 1:
81 case 2:
82 return state;
83 default:
84 throw new ArgumentException();
85 }
86 }
87  
88 public static implicit operator SplitState(string state)
89 {
90 return new SplitState(state);
91 }
92  
93 public static implicit operator string(SplitState state)
94 {
95 switch (state.State)
96 {
97 case 0:
98 return "Off";
99 case 1:
100 return "On";
101 case 2:
102 return "+5kHz";
103 default:
104 throw new ArgumentException();
105 }
106 }
107  
108 public static implicit operator SplitState(int state)
109 {
110 return new SplitState(state);
111 }
112  
113 public static implicit operator int(SplitState state)
114 {
115 return state.State;
116 }
117 }
118 }