-
Notifications
You must be signed in to change notification settings - Fork 66
/
ParameterInfoExtensions.cs
53 lines (50 loc) · 2.05 KB
/
ParameterInfoExtensions.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Newtonsoft.Json.Linq;
namespace MakeFunctionJson
{
internal static class ParameterInfoExtensions
{
/// <summary>
/// A parameter is an SDK parameter if it has at lease 1 SDK attribute.
/// </summary>
/// <param name="parameterInfo"></param>
/// <returns></returns>
public static bool IsWebJobSdkTriggerParameter(this ParameterDefinition parameterInfo)
{
return parameterInfo
.CustomAttributes
.Any(a => a.IsWebJobsAttribute() && a.ToAttributeFriendlyName().IndexOf("Trigger") > -1);
}
/// <summary>
/// Every parameter can be 1 to N bindings.
/// </summary>
/// <param name="parameterInfo">Has to be a WebJobSdkParameter <see cref="IsWebJobsSdkParameter(ParameterInfo)"/></param>
/// <returns></returns>
public static IEnumerable<JObject> ToFunctionJsonBindings(this ParameterDefinition parameterInfo)
{
return parameterInfo
.CustomAttributes
.Where(a => a.IsWebJobsAttribute()) // this has to return at least 1.
.Select(a => TypeUtility.GetResolvedAttribute(parameterInfo, a)) // For IConnectionProvider logic.
.Select(a => a.ToJObject()) // Convert the Attribute into a JObject.
.Select(obj =>
{
// Add a name property on the JObject that refers to the parameter name.
obj["name"] = parameterInfo.Name;
return obj;
})
.ToList();
}
/// <summary>
///
/// </summary>
/// <param name="parameterInfo"></param>
/// <returns></returns>
public static CustomAttribute GetDisabledAttribute(this ParameterDefinition parameterInfo)
{
return parameterInfo.CustomAttributes.FirstOrDefault(a => a.AttributeType.FullName == "Microsoft.Azure.WebJobs.DisableAttribute");
}
}
}