public static JProperty FindSingleChildProperty(this JToken startToken, string propertyName)
        {
            JProperty ret = null;
            var props = from JProperty p
                            in startToken.Children().OfType<JProperty>()
                        where p.Name.ToLower() == propertyName
                        select p;

            if (!props.Any())
            {
                foreach (var token in startToken.Children())
                {
                    ret = FindSingleChildProperty(token, propertyName);
                    if (ret != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                ret = props.ToArray()[0];
            }
            return ret;
        }
        public static JObject FindSingleChildObject(this JToken startToken, string objectName)
        {
            JObject ret = null;
            var props = from JObject o
                            in startToken.Children().OfType<JObject>()
                        where o["Name"].Value<string>() == objectName
                        select o;

            if (!props.Any())
            {
                foreach (var token in startToken.Children())
                {
                    ret = FindSingleChildObject(token, objectName);
                    if (ret != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                ret = props.ToArray()[0];
            }
            return ret;
        }
        /// <summary>
        /// Returns the children of the referenced page filtered for visitor. Returns 
        /// an empty collection if the reference is not resolvable.
        /// </summary>
        /// <param name="reference"></param>
        /// <returns></returns>
        public static PageDataCollection ChildrenForVisitor(this PageReference reference)
        {
            if (!reference.IsResolvable())
                return new PageDataCollection();

            return reference.Children().ForVisitor();
        }
示例#4
0
 public static string GetFieldHash(this JToken token)
 {
     var phi = token.Children().Cast<JProperty>().Select(s => s.Name).ToArray();
     var str = string.Join("", phi);
     var hash = str.GetHashCode().ToString();
     return hash;
 }
 public static IEnumerable<Transform> SelfChildren( this Transform transform )
 {
     yield return transform;
     foreach( var child in transform.Children() )
     {
     yield return child;
     }
 }
 public static void CheckAbsentRules(this Grammar grammar)
 {
     foreach (var rule in grammar.Children()) {
         if (grammar.Contains (rule) == false) {
             throw new NotImplementedException ();
         }
     }
 }
示例#7
0
 public static IEnumerable<YamlNode> ChildrenNamed(this YamlNode n, string name)
 {
     foreach (var child in n.Children())
     {
         if( child.Key.AsString() == name )
             yield return child.Value;
     }
 }
 public static XElement AddOrGet(this XElement element, string childElementName) {
     var result = element.Children(childElementName).FirstOrDefault();
     if (result == null) {
         result = new XElement(childElementName);
         element.Add(result);
     }
     return result;
 }
示例#9
0
        public static IEnumerable<Transform> Descendants( this Transform transform )
        {
            var descendants = transform.Children()
            .SelectMany( child => child.SelfDescendants() );

            foreach( var descendant in descendants )
            {
            yield return descendant;
            }
        }
        /// <summary>
        /// Search the JToken and its children recursively for a key that matches the given key.
        /// If such a key is found, set the value to the ref variable value and returns true.
        /// Otherwise, returns false.
        /// </summary>
        public static bool TryGetPropertyValue(this JToken propertiesJson, string key, ref string value)
        {
            if (propertiesJson == null)
            {
                return false;
            }

            if (propertiesJson.Type == JTokenType.Array)
            {
                foreach (JToken childToken in propertiesJson.Children())
                {
                    if (childToken.TryGetPropertyValue(key, ref value))
                    {
                        return true;
                    }
                }
            }
            else if (propertiesJson.Type == JTokenType.Object)
            {
                // We iterate through each child token of type JProperty, if the child token has
                // the same name as key, then we are done. Otherwise, recursively call this method
                // with the child token to continue the search.
                foreach (JProperty childProperty in propertiesJson.Children<JProperty>())
                {
                    if (string.Equals(childProperty.Name, key, StringComparison.OrdinalIgnoreCase))
                    {
                        value = childProperty.Value?.Value<string>();
                        return true;
                    }
                    if (childProperty.Value.TryGetPropertyValue(key, ref value))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
示例#11
0
        /// <summary>
        /// Gets specify child property value.
        /// </summary>
        /// <param name="jo">The payload in json format</param>
        /// <returns>The specify child property value.</returns>
        public static string GetChildPropertyValue(this JObject jo, string childPropertyName)
        {
            string value = null;

            if (jo != null)
            {
                foreach (var r in jo.Children<JProperty>())
                {
                    if (r.Name.Equals(childPropertyName, StringComparison.Ordinal))
                    {
                        value = r.Value.ToString().StripOffDoubleQuotes();
                        break;
                    }
                }
            }
            return value;
        }
示例#12
0
        /// <summary>
        /// 指定された条件式要素の子孫要素を取得します。
        /// </summary>
        /// <param name="element">条件式要素</param>
        /// <returns>条件式要素のコレクション</returns>
        public static IEnumerable<PredicateElement> Descendants(this PredicateElement element)
        {
            if (element == null)
                throw new ArgumentNullException(nameof(element));

            foreach (var child in element.Children())
            {
                yield return child;
                foreach (var grandChild in child.Descendants())
                    yield return grandChild;
            }
        }
 public static void Replace(this JObject jsonObject, string currentPropertyName, string newPropertyName, string newPropertyValue)
 {
     var oldProperty = jsonObject.Children<JProperty>().FirstOrDefault(z => z.Name == currentPropertyName);
     oldProperty.Replace(newPropertyName, newPropertyValue);
 }
 public static void RemoveField(this JObject o, string fieldName)
 {
     var Property = o.Children<JProperty>().FirstOrDefault(z => z.Name == fieldName);
     if (Property != null)
     {
         Property.Remove();
     }
 }
示例#15
0
 public static bool Contains(this JObject jo, string value)
 {
   return jo.Children().Where(v => (string)v == value).Count() > 0;
 }
 public static bool IsLoaded(this FrameworkElement frameworkElement)
 {
     return frameworkElement.Children().Count() > 0;
 }
示例#17
0
 private static CQ ReplaceOuterWith(this CQ element, CQ new_outer)
 {
     element.WrapInner (new_outer);
     return element.ReplaceWith (element.Children ());
 }
示例#18
0
文件: Skill.cs 项目: foxor/unity-nls
 public static IEnumerable<Skill> FindSkills(this XmlNode xn)
 {
     return xn.Children(SKILL).Map<Skill>(processNode);
 }
        /// <summary>
        /// Gets the children of the current Content entity relationships
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static IEnumerable<File> ChildrenAsFile(this EntityRelationCollection collection)
        {
            Mandate.ParameterNotNull(collection, "collection");

            return collection.Children<File>(FixedRelationTypes.FileRelationType);
        }
示例#20
0
 public static IEnumerable<XmlNode> GetStringNodes(this XmlNode xn)
 {
     return xn.Children(STRING);
 }
示例#21
0
 public static IEnumerable<Transform> SelfChildren( this Transform transform )
 {
     return new [] { transform }.Concat( transform.Children() );
 }
示例#22
0
        /// <summary>
        /// 指定された条件式要素自身とその子要素を取得します。
        /// </summary>
        /// <param name="element">条件式要素</param>
        /// <returns>条件式要素のコレクション</returns>
        public static IEnumerable<PredicateElement> ChildrenAndSelf(this PredicateElement element)
        {
            if (element == null)
                throw new ArgumentNullException(nameof(element));

            yield return element;
            foreach (var x in element.Children())
                yield return x;
        }
示例#23
0
 public static IQueryable<Content> OfType(this Content content, string contentTypeAlias)
 {
     return content.Children().OfType(contentTypeAlias);
 }
示例#24
0
 public static bool Contains(this JObject jo, DateTime value)
 {
   return jo.Children().Where(v => (DateTime)v == value).Count() > 0;
 }
示例#25
0
        /// <summary>
        /// Gets property value of named element (direct child) of Json object.
        /// </summary>
        /// <param name="jo">Json object</param>
        /// <param name="element">Name of element of Json object</param>
        /// <param name="propertyName">Name of the property</param>
        /// <returns>Literal string of the found property value of element if one can be found; null otherwise</returns>
        public static string GetPropertyOfElement(this JObject jo, string element, string propertyName)
        {
            string propertyValue = null;

            if (jo != null)
            {
                var items = from p in jo.Children<JProperty>()
                         where p.Name.Equals(element, StringComparison.Ordinal)
                         select p;

                var item = items.FirstOrDefault();
                if (item != null)
                {
                    var itemValue = item.Value;
                    if (itemValue != null)
                    {
                        if (itemValue.Type == JTokenType.Array && ((JArray)itemValue).Count > 0)
                        {
                            itemValue = itemValue.First();
                        }
                        var properties = from e in itemValue.Children<JProperty>()
                                 where e.Name.Equals(propertyName, StringComparison.Ordinal)
                                 select e;
                        if (properties.Count() > 0)
                        {
                            var typeVal = properties.First().Value;
                            if (typeVal.Type == JTokenType.String)
                            {
                                propertyValue = ((JValue)typeVal).Value.ToString();
                            }
                        }
                    }
                }
            }

            return propertyValue;
        }
示例#26
0
 public static bool Contains(this JObject jo, byte? value)
 {
   return jo.Children().Where(v => (byte?)v == value).Count() > 0;
 }
示例#27
0
 public static bool Contains(this JObject jo, decimal value)
 {
   return jo.Children().Where(v => (decimal)v == value).Count() > 0;
 }
 public static IReadOnlySet<PathSpec> Children(this PathSpec path)
 {
     return path.Children("*");
 }
示例#29
0
 /// <summary>
 /// Returns a collection of child elements of this node.
 /// </summary>
 public static IEnumerable<XmlNode> Elements(this XmlNode node)
 {
     if (node == null) throw new ArgumentNullException("node");
     return node.Children().Elements();
 }
示例#30
0
 public static IEnumerable<SkillPlan> FindSkillPlans(this XmlNode xn, Actor actor)
 {
     return xn.Children(SKILL_PLAN).Map<SkillPlan>(x => new SkillPlan(actor, x));
 }