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