HamBook – Blame information for rev

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