-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadJsonHelper.cs
More file actions
41 lines (37 loc) · 1.27 KB
/
ReadJsonHelper.cs
File metadata and controls
41 lines (37 loc) · 1.27 KB
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
using AzureDevopsTracker.Entities;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
namespace AzureDevopsTracker.Helpers
{
public static class ReadJsonHelper
{
public static IEnumerable<WorkItemCustomField> ReadJson(string workItemId, string jsonTexto)
{
try
{
JObject json = JObject.Parse(jsonTexto);
JObject? fields = json.SelectToken("resource.revision.fields") as JObject;
if (fields == null)
{
return Enumerable.Empty<WorkItemCustomField>();
}
var workItemCustomFields = new List<WorkItemCustomField>();
foreach (var property in fields.Properties())
{
if (property.Name.StartsWith("Custom."))
{
string key = property.Name["Custom.".Length..];
string value = property.Value.ToString();
workItemCustomFields.Add(new WorkItemCustomField(workItemId, key, value));
}
}
return workItemCustomFields;
}
catch
{
return [];
}
}
}
}