HamBook – Diff between revs 3 and 15
?pathlinks?
Rev 3 | Rev 15 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | using System; |
1 | using System; |
|
2 | using System.Collections.Generic; |
2 | using System.Collections.Generic; |
|
- | 3 | using System.ComponentModel; |
||
3 | using System.Linq; |
4 | using System.Linq; |
|
4 | using System.Text; |
5 | using System.Text; |
|
5 | using System.Threading.Tasks; |
6 | using System.Threading.Tasks; |
|
Line 6... | Line 7... | |||
6 | |
7 | |
|
7 | namespace HamBook.Radios.Generic |
8 | namespace HamBook.Radios.Generic |
|
8 | { |
9 | { |
|
9 | public enum RadioPhase |
10 | public class RadioPhase |
|
- | 11 | { |
||
- | 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) |
||
10 | { |
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 | { |
||
11 | SIMPLEX = 0, |
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: |
||
12 | PLUS_SHIFT, |
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; |
||
13 | MINUS_SHIFT |
111 | } |
|
14 | } |
112 | } |