Skip to content

Commit 1cc61e1

Browse files
committed
Convert public methods to extension methods
1 parent a152a09 commit 1cc61e1

2 files changed

Lines changed: 50 additions & 41 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace HttpMultipartParser
5+
{
6+
/// <summary>
7+
/// Class containing various extension methods.
8+
/// </summary>
9+
public static class Extensions
10+
{
11+
/// <summary>
12+
/// Returns true if the parameter has any values. False otherwise.
13+
/// </summary>
14+
/// <param name="parser">The multipart form parser.</param>
15+
/// <param name="name">The name of the parameter.</param>
16+
/// <returns>True if the parameter exists. False otherwise.</returns>
17+
public static bool HasParameter(this IMultipartFormDataParser parser, string name)
18+
{
19+
return parser.Parameters.Any(p => p.Name == name);
20+
}
21+
22+
/// <summary>
23+
/// Returns the value of a parameter or null if it doesn't exist.
24+
///
25+
/// You should only use this method if you're sure the parameter has only one value.
26+
///
27+
/// If you need to support multiple values use GetParameterValues.
28+
/// </summary>
29+
/// <param name="parser">The multipart form parser.</param>
30+
/// <param name="name">The name of the parameter.</param>
31+
/// <returns>The value of the parameter.</returns>
32+
public static string GetParameterValue(this IMultipartFormDataParser parser, string name)
33+
{
34+
return parser.GetParameterValues(name).FirstOrDefault();
35+
}
36+
37+
/// <summary>
38+
/// Returns the values of a parameter or an empty enumerable if the parameter doesn't exist.
39+
/// </summary>
40+
/// <param name="parser">The multipart form parser.</param>
41+
/// <param name="name">The name of the parameter.</param>
42+
/// <returns>The values of the parameter.</returns>
43+
public static IEnumerable<string> GetParameterValues(this IMultipartFormDataParser parser, string name)
44+
{
45+
return parser.Parameters
46+
.Where(p => p.Name == name)
47+
.Select(p => p.Data);
48+
}
49+
}
50+
}

Source/HttpMultipartParser/MultipartFormDataParser.cs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -244,47 +244,6 @@ public static async Task<MultipartFormDataParser> ParseAsync(Stream stream, stri
244244

245245
#endregion
246246

247-
#region Public Methods
248-
249-
/// <summary>
250-
/// Returns true if the parameter has any values. False otherwise.
251-
/// </summary>
252-
/// <param name="name">The name of the parameter.</param>
253-
/// <returns>True if the parameter exists. False otherwise.</returns>
254-
public bool HasParameter(string name)
255-
{
256-
return Parameters.Any(p => p.Name == name);
257-
}
258-
259-
/// <summary>
260-
/// Returns the value of a parameter or null if it doesn't exist.
261-
///
262-
/// You should only use this method if you're sure the parameter has only one value.
263-
///
264-
/// If you need to support multiple values use GetParameterValues.
265-
/// </summary>
266-
/// <param name="name">The name of the parameter.</param>
267-
/// <returns>The value of the parameter.</returns>
268-
public string GetParameterValue(string name)
269-
{
270-
var parameter = Parameters.FirstOrDefault(p => p.Name == name);
271-
return parameter?.Data;
272-
}
273-
274-
/// <summary>
275-
/// Returns the values of a parameter or an empty enumerable if the parameter doesn't exist.
276-
/// </summary>
277-
/// <param name="name">The name of the parameter.</param>
278-
/// <returns>The values of the parameter.</returns>
279-
public IEnumerable<string> GetParameterValues(string name)
280-
{
281-
return Parameters
282-
.Where(p => p.Name == name)
283-
.Select(p => p.Data);
284-
}
285-
286-
#endregion
287-
288247
#region Private Methods
289248

290249
/// <summary>

0 commit comments

Comments
 (0)