-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathActionFunctions.Parameters.cs
38 lines (33 loc) · 1.42 KB
/
ActionFunctions.Parameters.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections.Generic;
using System.Linq;
namespace NTypewriter.CodeModel.Functions
{
/// <summary>
/// Set of functions that operates on IMethod
/// </summary>
public static partial class ActionFunctions
{
/// <summary>
/// Returns parameters that receive content sent to a webapi action.
/// If _includeBodyParameter_ is specified as false, then the Parameter list returned will not include the parameter that is being sent in the body of the request.
/// </summary>
public static IEnumerable<IParameter> Parameters(this IMethod method, bool includeBodyParameter = true)
{
var parameterTypeBlackList = new[] { "CancellationToken" };
var parameterAttributeBlackList = new[] { "FromServices" };
var dataParameters = method.Parameters
.Where(x => !parameterTypeBlackList.Contains(x.Type.Name))
.Where(x => x.Attributes.All(y => !parameterAttributeBlackList.Contains(y.Name)))
.ToList();
if (!includeBodyParameter)
{
var bodyParameter = method.BodyParameter();
if (bodyParameter != null)
{
return dataParameters.Where(p => p.Name != bodyParameter.Name).ToList();
}
}
return dataParameters.ToList();
}
}
}