Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryParse() [1/2]

static bool System.Net.NetworkInformation.PhysicalAddress.TryParse ( ReadOnlySpan< char > address,
[NotNullWhen(true)] out PhysicalAddress? value )
inlinestatic

Definition at line 112 of file PhysicalAddress.cs.

113 {
114 char? c = null;
115 value = null;
116 byte[] array;
117 int value2;
118 if (address.Contains('-'))
119 {
120 if ((address.Length + 1) % 3 != 0)
121 {
122 return false;
123 }
124 c = '-';
125 array = new byte[(address.Length + 1) / 3];
126 value2 = 2;
127 }
128 else if (address.Contains(':'))
129 {
130 c = ':';
131 if (!TryGetValidSegmentLength(address, ':', out value2))
132 {
133 return false;
134 }
135 if (value2 != 2 && value2 != 4)
136 {
137 return false;
138 }
139 array = new byte[6];
140 }
141 else if (address.Contains('.'))
142 {
143 c = '.';
144 if (!TryGetValidSegmentLength(address, '.', out value2))
145 {
146 return false;
147 }
148 if (value2 != 4)
149 {
150 return false;
151 }
152 array = new byte[6];
153 }
154 else
155 {
156 if (address.Length % 2 > 0)
157 {
158 return false;
159 }
160 value2 = address.Length;
161 array = new byte[address.Length / 2];
162 }
163 int num = 0;
164 int num2 = 0;
165 for (int i = 0; i < address.Length; i++)
166 {
167 int num3 = address[i];
168 int num4;
169 if ((num4 = System.HexConverter.FromChar(num3)) == 255)
170 {
171 if (c == num3 && num == value2)
172 {
173 num = 0;
174 continue;
175 }
176 return false;
177 }
178 num3 = num4;
179 if (num >= value2)
180 {
181 return false;
182 }
183 if (num % 2 == 0)
184 {
185 array[num2] = (byte)(num3 << 4);
186 }
187 else
188 {
189 array[num2++] |= (byte)num3;
190 }
191 num++;
192 }
193 if (num < value2)
194 {
195 return false;
196 }
198 return true;
199 }
static int FromChar(int c)
static bool TryGetValidSegmentLength(ReadOnlySpan< char > address, char delimiter, out int value)

References System.Net.NetworkInformation.PhysicalAddress.PhysicalAddress(), System.array, System.HexConverter.FromChar(), System.ReadOnlySpan< T >.Length, System.Net.NetworkInformation.PhysicalAddress.TryGetValidSegmentLength(), and System.value.