AD2 parsing, PFH parsing, PFL parsing.
This commit is contained in:
33
BodyshopUploader/Utils/JsonExtensions.cs
Normal file
33
BodyshopUploader/Utils/JsonExtensions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BodyshopUploader.Utils
|
||||
{
|
||||
public static class JsonExtensions
|
||||
{
|
||||
public static void RemovePropertiesByValue(this JToken root, Predicate<JValue> filter)
|
||||
{
|
||||
var nulls = root.DescendantsAndSelf().OfType<JValue>().Where(v => v.Parent is JProperty && filter(v)).ToList();
|
||||
foreach (var value in nulls)
|
||||
{
|
||||
var parent = (JProperty)value.Parent;
|
||||
parent.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<JToken> DescendantsAndSelf(this JToken node)
|
||||
{
|
||||
if (node == null)
|
||||
return Enumerable.Empty<JToken>();
|
||||
var container = node as JContainer;
|
||||
if (container != null)
|
||||
return container.DescendantsAndSelf();
|
||||
else
|
||||
return new[] { node };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user