77
88namespace WGetNET . HelperClasses
99{
10+ /// <summary>
11+ /// Handels the parsing of strings to a <see cref="System.Version"/> instance.
12+ /// </summary>
1013 internal static class VersionParser
1114 {
15+ /// <summary>
16+ /// Parses a <see cref="System.String"/> to a <see cref="System.Version"/> instance as best as possible.
17+ /// </summary>
18+ /// <param name="input">The <see cref="System.String"/> to parse.</param>
19+ /// <returns>
20+ /// The created <see cref="System.Version"/> instance.
21+ /// </returns>
1222 public static Version Parse ( string input )
1323 {
1424 if ( string . IsNullOrWhiteSpace ( input ) )
@@ -24,6 +34,16 @@ public static Version Parse(string input)
2434 return CleanParse ( input ) ;
2535 }
2636
37+ /// <summary>
38+ /// Parses a <see cref="System.String"/> to a <see cref="System.Version"/> instance as best as possible.
39+ /// </summary>
40+ /// <remarks>
41+ /// This tries to resolve the string one by one to parse it.
42+ /// </remarks>
43+ /// <param name="input">The <see cref="System.String"/> to parse.</param>
44+ /// <returns>
45+ /// The created <see cref="System.Version"/> instance.
46+ /// </returns>
2747 private static Version CleanParse ( string input )
2848 {
2949 string [ ] versionParts = input . Split ( '.' ) ;
@@ -67,6 +87,14 @@ private static Version CleanParse(string input)
6787 }
6888 }
6989
90+ /// <summary>
91+ /// Parses a <see cref="System.String"/> to a <see cref="System.Int32"/> as best as possible.
92+ /// </summary>
93+ /// <param name="input">The <see cref="System.String"/> to parse.</param>
94+ /// <param name="defaultValue">Default value that is used if the input can't be parsed.</param>
95+ /// <returns>
96+ /// The created <see cref="System.Int32"/>.
97+ /// </returns>
7098 private static int ParseToInt ( string input , int defaultValue = 0 )
7199 {
72100 if ( int . TryParse ( input , out int result ) )
@@ -77,6 +105,18 @@ private static int ParseToInt(string input, int defaultValue = 0)
77105 return CleanParseToInt ( input , defaultValue ) ;
78106 }
79107
108+ /// <summary>
109+ /// Parses a <see cref="System.String"/> to a <see cref="System.Int32"/> as best as possible.
110+ /// </summary>
111+ /// <remarks>
112+ /// This tries to clean the provided input <see cref="System.String"/>,
113+ /// with minimal data loss, so it can be parsed to a <see cref="System.Int32"/>
114+ /// </remarks>
115+ /// <param name="input">The <see cref="System.String"/> to parse.</param>
116+ /// <param name="defaultValue">Default value that is used if the input can't be parsed.</param>
117+ /// <returns>
118+ /// The created <see cref="System.Int32"/>.
119+ /// </returns>
80120 private static int CleanParseToInt ( string input , int defaultValue = 0 )
81121 {
82122 string cleanInput = CleanupNumberString ( input ) ;
@@ -89,6 +129,16 @@ private static int CleanParseToInt(string input, int defaultValue = 0)
89129 return defaultValue ;
90130 }
91131
132+ /// <summary>
133+ /// Cleans a <see cref="System.String"/>, with minimal version information loss, so it can be parsed to a <see cref="System.Int32"/>.
134+ /// </summary>
135+ /// <remarks>
136+ /// If the <see cref="System.String"/> looks lick this '123ABC456' it will not be cleaned, because to much information will be lost.
137+ /// </remarks>
138+ /// <param name="input">The <see cref="System.String"/> to clean up.</param>
139+ /// <returns>
140+ /// The processed <see cref="System.String"/>:
141+ /// </returns>
92142 private static string CleanupNumberString ( string input )
93143 {
94144 // Remove appendix (e.g. 123456-preview1) becaue it could contain a mix of numbers and letters,
@@ -120,6 +170,16 @@ private static string CleanupNumberString(string input)
120170 return cleanString . ToString ( ) ;
121171 }
122172
173+ /// <summary>
174+ /// Removes version appendixes from the string.
175+ /// </summary>
176+ /// <remarks>
177+ /// An version appendix could look like this: '-preview', '-beta2' or '-pre'.
178+ /// </remarks>
179+ /// <param name="input">The <see cref="System.String"/> to process.</param>
180+ /// <returns>
181+ /// The processed <see cref="System.String"/>.
182+ /// </returns>
123183 private static string RemoveAppendix ( string input )
124184 {
125185 string [ ] parts = input . Split ( '-' ) ;
0 commit comments