Ejemplo n.º 1
0
        static IImmutableStack <T> GetPrevElementInHierarchyCore <T>(IImmutableStack <T> rootStack, Func <T, IList <T> > getChildren, Func <IList <T>, T, int> indedOf) where T : class
        {
            var currentElement = rootStack.Peek();

            Func <T, IEnumerable <T> > getChildrenPath = element => LinqExtensions.Unfold(element, x => getChildren(x).LastOrDefault(), x => x == null);

            var parents = rootStack.Pop();
            var parent  = parents.FirstOrDefault();

            if (parent == null)
            {
                return(ImmutableStack.Empty <T>().PushMultiple(getChildrenPath(currentElement)));
            }

            var neighbors = getChildren(parent);
            var index     = indedOf(neighbors, currentElement);

            if (index > 0)
            {
                return(parents.PushMultiple(getChildrenPath(neighbors[index - 1])));
            }

            return(parents);
        }
 static IEnumerable <Type> GetAttributeTypes(Attribute attr)
 {
     return(LinqExtensions.Unfold(attr.GetType(), x => x.BaseType, x => x == typeof(Attribute)));
 }