Ejemplo n.º 1
0
        private static IEnumerable<XmlExpression> AcquireChildren(XmlExpression expression)
        {
            foreach (var property in expression.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.Name == "Parent")
                    continue;

                if (typeof(XmlExpression).IsAssignableFrom(property.PropertyType))
                {
                    yield return (XmlExpression)property.GetValue(expression, null);
                }

                if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
                {
                    var enumerable = (IEnumerable)property.GetValue(expression, null);
                    if (enumerable == null)
                        continue;

                    foreach(var entry in enumerable)
                    {
                        if (entry is XmlExpression)
                        {
                            yield return (XmlExpression)entry;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Expression ToExpression(XmlExpression source)
        {
            if (source == null)
                return null;

            FillParentRecursive(source.Parent, source);
            return source.ToExpression();
        }
Ejemplo n.º 3
0
 private static void FillParentRecursive(XmlExpression parent, XmlExpression child)
 {
     if (child != null)
     {
         child.Parent = parent;
         foreach (var grandChild in AcquireChildren(child))
         {
             FillParentRecursive(child, grandChild);
         }
     }
 }