-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathAdaptiveCardUtil.cs
37 lines (33 loc) · 1.34 KB
/
AdaptiveCardUtil.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
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace Bot.Builder.Community.Cards
{
internal static class AdaptiveCardUtil
{
private static readonly string[] InputTypes = new[]
{
AdaptiveInputTypes.ChoiceSet,
AdaptiveInputTypes.Date,
AdaptiveInputTypes.Number,
AdaptiveInputTypes.Text,
AdaptiveInputTypes.Time,
AdaptiveInputTypes.Toggle,
};
internal static IEnumerable<JToken> NonDataDescendants(JContainer container) =>
container?.Descendants().Where(token =>
!token.Ancestors().Any(ancestor =>
(ancestor as JProperty)?.Name.Equals(
AdaptiveProperties.Data) == true));
internal static IEnumerable<JObject> GetAdaptiveInputs(JContainer container)
{
return NonDataDescendants(container)?
.Select(token => token is JObject element
&& InputTypes.Contains(element.GetValue(AdaptiveProperties.Type)?.ToString())
&& element.GetValue(AdaptiveProperties.Id) != null ? element : null)
.WhereNotNull();
}
internal static string GetAdaptiveInputId(JObject input) => input?.GetValue(AdaptiveProperties.Id)?.ToString();
}
}