Skip to content

Commit a1bc6f3

Browse files
authored
[Xamarin.MacDev] Split IAppleSdkVersion.TryParse in two methods. (#73)
Split IAppleSdkVersion.TryParse into two methods, one that outputs the parsed int array and one that outputs the actual IAppleSdkVersion. This way we can re-use the actual version validation by using the int array overload when we're not interested in the actual version output.
1 parent 45c5a68 commit a1bc6f3

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Xamarin.MacDev/IAppleSdkVersion.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,36 @@ public static IAppleSdkVersion GetDefault (this IAppleSdkVersion @this, IAppleSd
1818
return v.Count > 0 ? v [v.Count - 1] : @this.GetUseDefault ();
1919
}
2020

21-
public static bool TryParse<T> (string s, out T result) where T : IAppleSdkVersion, new()
21+
public static bool TryParse (string s, out int[] result)
2222
{
23-
result = new T ();
24-
if (s == null)
23+
if (s == null) {
24+
result = null;
2525
return false;
26+
}
2627

2728
var vstr = s.Split ('.');
28-
var vint = new int [vstr.Length];
29+
result = new int [vstr.Length];
2930

3031
for (int j = 0; j < vstr.Length; j++) {
3132
int component;
3233
if (!int.TryParse (vstr [j], out component))
3334
return false;
3435

35-
vint [j] = component;
36+
result [j] = component;
3637
}
3738

39+
return true;
40+
}
41+
42+
public static bool TryParse<T> (string s, out T result) where T : IAppleSdkVersion, new()
43+
{
44+
result = new T ();
45+
if (s == null)
46+
return false;
47+
48+
if (!TryParse (s, out var vint))
49+
return false;
50+
3851
result.SetVersion (vint);
3952
return true;
4053
}

0 commit comments

Comments
 (0)