当前位置: 首页>>代码示例>>C#>>正文


C# JToken.Children方法代码示例

本文整理汇总了C#中JToken.Children方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.Children方法的具体用法?C# JToken.Children怎么用?C# JToken.Children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JToken的用法示例。


在下文中一共展示了JToken.Children方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RedactInformationRecursive

        private static JToken RedactInformationRecursive(JToken check, List<string> keys = null)
        {

            if (keys == null) keys = new List<string>(){"password", "passwd", 
                                                        "pass","api_key","api_token","access_key", 
                                                        "secret_key", "private_key","secret"};

            if (check.Children().Any())
            {
                foreach (var child in check.Children())
                {

                    RedactInformationRecursive(child, keys);

                    if (child.Type == JTokenType.Property)
                    {
                        var property = child as Newtonsoft.Json.Linq.JProperty;
                        
                        if (keys.Contains(property.Name))
                        {
                            property.Value = "REDACTED";
                        }      
                    }
                    
                }    
            }
            return check;
        }
开发者ID:dogtbh,项目名称:sensu-client,代码行数:28,代码来源:SensuClientHelper.cs

示例2: ChangeObject

        /// <summary>
        /// Applies changes to a JToken
        /// </summary>
        /// <param name="objectToChange">
        /// The object to change
        /// </param>
        /// <param name="fields">
        /// The fields that changed
        /// </param>
        /// <param name="cleared">
        /// The fields that were cleared
        /// </param>
        public void ChangeObject(JToken objectToChange, Dictionary<string, JToken> fields, string[] cleared)
        {
            if (fields != null)
            {
                foreach (var changedField in fields)
                {
                    var fieldToChange =
                        objectToChange.Children<JProperty>().SingleOrDefault(x => x.Name == changedField.Key);

                    if (fieldToChange != null)
                    {
                        fieldToChange.Value = changedField.Value;
                    }
                }
            }

            if (cleared != null)
            {
                foreach (var clearedField in cleared)
                {
                    var fieldToRemove = objectToChange.Children<JProperty>()
                        .SingleOrDefault(x => x.Name == clearedField);

                    if (fieldToRemove != null)
                    {
                        fieldToRemove.Remove();
                    }
                }
            }
        }
开发者ID:Lavan,项目名称:DdpNet,代码行数:42,代码来源:UntypedObjectChanger.cs

示例3: IsBasicNode

 private static bool IsBasicNode(JToken node)
 {
     if (node.Children().Count() != 1)
         return false;
     if (node.Children().First().Children().Count() != 0)
         return false;
     return true;
 }
开发者ID:nishantsgs,项目名称:AvaTaxTestCaseRunner,代码行数:8,代码来源:JsonComparer.cs

示例4: WalkNode

        static bool WalkNode(JToken node, Action<JObject> action, bool skipRed = false)
        {
            if (node.Type == JTokenType.Object)
            {
                action((JObject)node);

                int totalBeforeRed = total;

                foreach (JProperty child in node.Children<JProperty>())
                {
                    if (!WalkNode(child.Value, action, skipRed))
                    {
                        if (skipRed)
                        {
                            total = totalBeforeRed;
                            break;
                        }
                    }
                }
            }
            else if (node.Type == JTokenType.Array)
            {
                int totalBeforeRed = total;

                foreach (JToken child in node.Children())
                {
                    if (!WalkNode(child, action, skipRed))
                    {
                        if (skipRed)
                        {
                            total = totalBeforeRed;
                            break;
                        }
                    }
                }
            }
            else
            {
                if (node.Type == JTokenType.String)
                {
                    if (node.Parent.Type != JTokenType.Array)
                    {
                        if (node.Value<string>() == "red")
                        {
                            return false;
                        }
                    }
                }

                if (node.Type == JTokenType.Integer)
                {
                    total += node.Value<int>();
                }
            }

            return true;
        }
开发者ID:KoalaBear84,项目名称:AdventOfCode2015,代码行数:57,代码来源:Program.cs

示例5: Apply

        public JToken Apply(JToken filtered, IFilterContext context)
        {
            // if they have 6 and we want 2 then skip to index 4 (exclusive)
            int toIndex = filtered.Children().Count() - _limit;

            foreach (var child in filtered.Children().Take(toIndex).ToList())
            {
                child.Remove();
            }

            return filtered;
        }
开发者ID:Dev01FC,项目名称:CnC-SC,代码行数:12,代码来源:LimitToLastFilter.cs

示例6: FindEncryptedTokens

        private static void FindEncryptedTokens(JToken containerToken, List<JToken> matches)
        {
            if (containerToken.Type == JTokenType.Object)
            {
                var children = containerToken.Children<JProperty>();
                if (children.Count() == 2)
                {
                    if(children.First().Name == "IV" && children.Last().Name == "Value")
                    {
                        matches.Add(containerToken);
                    }
                    else if (children.First().Name == "IV" && children.Last().Name == "Password")
                    {
                        throw new ConDepCryptoException(@"
            Looks like you have an older environment encryption from an earlier version of ConDep. To correct this please replace ""Password"" key with ""Value"" in your Environment file(s). Example :
            ""IV"": ""SaHK0yzgwDSAtE/oOhW0qg=="",
            ""Password"": ""Dcyn8fXnGnIG5rUw0BufzA==""

            replace ""Password"" key with ""Value"" like this:

            ""IV"": ""SaHK0yzgwDSAtE/oOhW0qg=="",
            ""Value"": ""Dcyn8fXnGnIG5rUw0BufzA==""
            ");
                    }
                    else
                    {
                        foreach (JProperty child in children)
                        {
                            FindEncryptedTokens(child.Value, matches);
                        }
                    }
                }
                else
                {
                    foreach (JProperty child in containerToken.Children<JProperty>())
                    {
                        FindEncryptedTokens(child.Value, matches);
                    }
                }

            }
            else if (containerToken.Type == JTokenType.Array)
            {
                foreach (JToken child in containerToken.Children())
                {
                    FindEncryptedTokens(child, matches);
                }
            }
        }
开发者ID:condep,项目名称:condep-execution,代码行数:49,代码来源:JsonExtensions.cs

示例7: MergeInto

        public static void MergeInto(this JContainer left, JToken right)
        {
            foreach (var rightChild in right.Children<JProperty>())
            {
                var rightChildProperty = rightChild;
                var path = string.Empty.Equals(rightChildProperty.Name) || rightChildProperty.Name.Contains(" ")
                    ? $"['{rightChildProperty.Name}']"
                    : rightChildProperty.Name;

                var leftProperty = left.SelectToken(path);
                if (leftProperty == null)
                {
                    // no matching property, just add 
                    left.Add(rightChild);
                }
                else
                {
                    var leftObject = leftProperty as JObject;
                    if (leftObject == null)
                    {
                        // replace value
                        var leftParent = (JProperty)leftProperty.Parent;
                        leftParent.Value = rightChildProperty.Value;
                    }
                    else
                        MergeInto(leftObject, rightChildProperty.Value);
                }
            }
        }
开发者ID:MassTransit,项目名称:MassTransit,代码行数:29,代码来源:JsonExtensions.cs

示例8: CleanObject

        private static void CleanObject(JToken token)
        {
            var list = new Dictionary<JToken, JProperty>();

            if (token.GetType() != typeof(JObject))
                return;

            // remove the results nodes
            var childrenWithResults = token.Children<JProperty>()
                .Where(c => c.Children<JObject>()["results"].Count() > 0).ToList();

            foreach(var child in childrenWithResults)
            {
                var resultsProperty = child.Children()["results"];
                var newProperty = new JProperty(child.Name, resultsProperty.Children());
                child.Replace(newProperty);
            }

            // remove __deferred properties
            var deferredChildren = token.Children<JProperty>()
                .Where(c => c.Children<JObject>()["__deferred"].Count() > 0).ToList();

            foreach(var deferred in deferredChildren)
            {
                deferred.Remove();
            }
        }
开发者ID:RobTillie,项目名称:exactonline-api-dotnet-client,代码行数:27,代码来源:ApiResponseCleaner.cs

示例9: MergeInto

        public static void MergeInto(this JContainer left, JToken right)
        {
            foreach (JProperty rightChild in right.Children<JProperty>())
            {
                JProperty rightChildProperty = rightChild;
                JToken leftProperty = left.SelectToken(rightChildProperty.Name);

                if (leftProperty == null)
                {
                    // no matching property, just add 
                    left.Add(rightChild);
                }
                else
                {
                    var leftObject = leftProperty as JObject;
                    if (leftObject == null)
                    {
                        // replace value
                        var leftParent = (JProperty)leftProperty.Parent;
                        leftParent.Value = rightChildProperty.Value;
                    }
                    else
                        // recurse object
                        MergeInto(leftObject, rightChildProperty.Value);
                }
            }
        }
开发者ID:kotvisbj,项目名称:MassTransit,代码行数:27,代码来源:JsonExtensions.cs

示例10: MapAggregateJsonToPayroll

 public Payroll[] MapAggregateJsonToPayroll(JToken aggregatePayrollJson, JToken expensesJson = null)
 {
     var payrollItems = new List<Payroll>();
     foreach (JToken j in aggregatePayrollJson.Children()) {
         payrollItems.Add(MapJsonToPayroll(j, expensesJson));
     }
     return payrollItems.ToArray();
 }
开发者ID:ahaley,项目名称:AtTask,代码行数:8,代码来源:PayrollMapper.cs

示例11: MergeInto

        /// <summary>
        /// <para>Merge the right token into the left</para>
        /// </summary>
        /// <param name="left">Token to be merged into</param>
        /// <param name="right">Token to merge, overwriting the left</param>
        /// <param name="options">Options for merge</param>
        public static void MergeInto(
            this JContainer left, JToken right, MergeOptions options)
        {
            foreach (var rightChild in right.Children<JProperty>())
            {
                var rightChildProperty = rightChild;
                var leftPropertyValue = left.SelectToken(rightChildProperty.Name);

                // add on demand only. This will keep low memory usage.
                if (leftPropertyValue == null && options.ADD_NONE_EXISTING)
                {
                    // no matching property, just add
                    left.Add(rightChild);
                }
                else
                {
                    if (leftPropertyValue == null && !options.ADD_NONE_EXISTING)
                    {
                        // becoz we don't want to add so continue checking for next property.
                        continue;
                    }
                    var leftProperty = (JProperty)leftPropertyValue.Parent;
                    var leftArray = leftPropertyValue as JArray;
                    var rightArray = rightChildProperty.Value as JArray;
                    if (leftArray != null && rightArray != null)
                    {
                        switch (options.ArrayHandling)
                        {
                            case MergeOptionArrayHandling.Concat:
                                foreach (var rightValue in rightArray)
                                {
                                    leftArray.Add(rightValue);
                                }
                                break;
                            case MergeOptionArrayHandling.Overwrite:

                                leftProperty.Value = rightChildProperty.Value;
                                break;
                        }
                    }
                    else
                    {
                        var leftObject = leftPropertyValue as JObject;
                          //only set property if it not null
                        if (leftObject == null && !string.IsNullOrEmpty(rightChildProperty.Value.ToString()))
                        {
                            // replace value
                            leftProperty.Value = rightChildProperty.Value;
                        }

                        else
                            // recurse object
                            MergeInto(leftObject, rightChildProperty.Value, options);
                    }
                }
            }
        }
开发者ID:ramkumar013,项目名称:ECMS,代码行数:63,代码来源:MergeExtensions.cs

示例12: AllChildren

 // Recursively yield all children of json
 private static IEnumerable<JToken> AllChildren(JToken json)
 {
     foreach (var c in json.Children()) {
         yield return c;
         foreach (var cc in AllChildren(c)) {
             yield return cc;
         }
     }
 }
开发者ID:travusgonzalez,项目名称:dcs-challenge,代码行数:10,代码来源:EmailProcessor.cs

示例13: SetRequestData

 public RequestWrapper SetRequestData(JToken values)
 {
     if (values != null)
     {
         foreach (JProperty item in values.Children())
             if (item != null) this[item.Name] = item.Value.ToString();
     }
     return this;
 }
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:9,代码来源:RequestWrapperMethods.cs

示例14: Apply

        public JToken Apply(JToken filtered, IFilterContext context)
        {
            foreach (var child in filtered.Children().Skip(_limit).ToList())
            {
                child.Remove();
            }

            return filtered;
        }
开发者ID:Dev01FC,项目名称:CnC-SC,代码行数:9,代码来源:LimitToFirstFilter.cs

示例15: FromJson

        public static Result FromJson(JToken actionIdToken, JToken resultToken)
        {
            var actionId = actionIdToken.Value<Int32>();
            var properties = ResultProperty
                .FromJson(resultToken.Children())
                .ToList();

            return new Result(actionId, properties);
        }
开发者ID:dstarkowski,项目名称:csom-inspector,代码行数:9,代码来源:Result.cs


注:本文中的JToken.Children方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。