Пример #1
0
 public static IEnumerable <Object> ToEnumerable(this IHasChildren <Object> root)
 {
     return(root.Children.Concat(
                root.Children
                .OfType <IHasChildren <Object> >()
                .SelectMany(ToEnumerable)));
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualTreeGridItem"/> class.
 /// </summary>
 /// <param name="category">The category.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="kind">The kind.</param>
 public VirtualTreeGridItem(VirtualTreeGridCategory category, IHasChildren parent, ModelKind kind)
 {
     this.category = category;
     this.parent   = parent;
     this.kind     = kind;
     tempName      = EmptyName;
 }
Пример #3
0
        private bool TryGetByNameInner <T>(IHasChildren <object> currentParent, string subname, out T result) where T : class
        {
            if (subname == null)
            {
                result = null;
                return(false);
            }
            var    parts = subname.Split(new [] { Machine.PathSeparator }, 2);
            object candidate;

            if (!currentParent.TryGetByName(parts[0], out candidate))
            {
                result = null;
                return(false);
            }
            result = candidate as T;
            if (parts.Length == 1)
            {
                return(result != null);
            }
            var parent = candidate as IHasChildren <object>;

            if (parent != null)
            {
                return(TryGetByNameInner(parent, parts[1], out result));
            }
            return(false);
        }
Пример #4
0
        public static bool TryGetByName <T>(this IHasChildren <T> @this, string name, out T child)
        {
            bool success;

            child = @this.TryGetByName(name, out success);
            return(success);
        }
 public static dynamic GetTSObject(IHasChildren dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualTreeGridItem"/> class.
 /// </summary>
 /// <param name="category">The category.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="data">The data.</param>
 /// <param name="kind">The kind.</param>
 public VirtualTreeGridItem(VirtualTreeGridCategory category, IHasChildren parent, ITypeMember data,
                            ModelKind kind)
 {
     this.category = category;
     DataItem      = data;
     this.parent   = parent;
     this.kind     = kind;
 }
Пример #7
0
        /// <summary>
        /// Similar to Linq's Count(), but deep searches the parent, applying the predicate to the parent's children, its children's children, etc.
        /// </summary>
        public static int DeepCountChildren <T>(this IHasChildren <T> objParent, Func <T, bool> predicate) where T : IHasChildren <T>
        {
            int intReturn = objParent.Children.Count(predicate);

            foreach (IHasChildren <T> objLoopChild in objParent.Children)
            {
                intReturn += objLoopChild.DeepCountChildren(predicate);
            }
            return(intReturn);
        }
Пример #8
0
        /// <summary>
        /// Remplissage de l'arbre
        /// </summary>
        /// <param name="elem">The elem.</param>
        /// <param name="headerName">Name of the header.</param>
        /// <param name="categories">The categories.</param>
        public void BindData(IHasChildren elem, string headerName, List <VirtualTreeGridCategory> categories)
        {
            Debug.Assert(elem != null);
            Debug.Assert(categories != null && categories.Count > 0);

            _root       = elem;
            _title      = headerName;
            _categories = categories;
            RefreshData();
        }
Пример #9
0
        /// <summary>
        /// Similar to Linq's Where(), but deep searches the parent, applying the predicate to the parent's children, its children's children, etc.
        /// </summary>
        public static IEnumerable <T> GetAllDescendants <T>(this IHasChildren <T> objParent) where T : IHasChildren <T>
        {
            List <T> objReturn = new List <T>();

            objReturn.AddRange(objParent.Children);
            foreach (IHasChildren <T> objLoopChild in objParent.Children)
            {
                objReturn.AddRange(objLoopChild.GetAllDescendants());
            }
            return(objReturn);
        }
Пример #10
0
        /// <summary>
        /// Similar to Linq's Where(), but deep searches the parent, applying the predicate to the parent's children, its children's children, etc.
        /// </summary>
        public static IEnumerable <T> DeepWhere <T>(this IHasChildren <T> objParent, Func <T, bool> predicate) where T : IHasChildren <T>
        {
            List <T> objReturn = new List <T>();

            objReturn.AddRange(objParent.Children.Where(predicate));
            foreach (IHasChildren <T> objLoopChild in objParent.Children)
            {
                objReturn.AddRange(objLoopChild.DeepWhere(predicate));
            }
            return(objReturn);
        }
Пример #11
0
 public static IEnumerable <StepsContainer> FlattenStepsContainers(this IHasChildren featureOrRule)
 {
     foreach (var featureChild in featureOrRule.Children)
     {
         if (featureChild is StepsContainer stepsContainer)
         {
             yield return(stepsContainer);
         }
         else if (featureChild is IHasChildren containerNode)
         {
             foreach (var ruleStepsContainer in containerNode.StepsContainers())
             {
                 yield return(ruleStepsContainer);
             }
         }
     }
 }
Пример #12
0
        /*
         * WIP version of the generic form of the above, where I can could use a function pointer instead of having to rely on IHasChildren<T> (and why this file is called LinqExtensions
         * /// <summary>
         * /// Similar to Linq's Count(), but deep searches the list, applying the predicate to the parents, the parents' children, their children's children, etc.
         * /// </summary>
         * public static int DeepCount<T>(this IEnumerable<T> objParentList, Func<IEnumerable<T>> funcGetChildrenMethod, Func<T, bool> predicate)
         * {
         *  int intReturn = objParentList.Count(predicate);
         *  foreach (IHasChildren<T> objLoopChild in objParentList)
         *  {
         *      intReturn += funcGetChildrenMethod().DeepCount(funcGetChildrenMethod, predicate);
         *  }
         *  return intReturn;
         * }
         */

        /// <summary>
        /// Similar to Linq's FirstOrDefault(), but deep searches the parent, applying the predicate to the parent's children, its children's children, etc.
        /// </summary>
        public static T DeepFirstOrDefault <T>(this IHasChildren <T> objParent, Func <T, bool> predicate) where T : IHasChildren <T>
        {
            T objReturn = objParent.Children.FirstOrDefault(predicate);

            if (objReturn?.Equals(default(T)) == false)
            {
                return(objReturn);
            }
            foreach (IHasChildren <T> objLoopChild in objParent.Children)
            {
                objReturn = objLoopChild.DeepFirstOrDefault(predicate);
                if (objReturn?.Equals(default(T)) == false)
                {
                    return(objReturn);
                }
            }
            return(default(T));
        }
 private IEnumerable <ControlFlowBase> createChildren(IHasChildren <ControlFlowElementBase> controlFlow)
 {
     return(controlFlow.Children.Select(Create).ToArray());
 }
Пример #14
0
        protected virtual void Build(List <Pickle> pickles, string language, IEnumerable <Tag> tags, IEnumerable <PickleStep> parentBackgroundSteps, IHasChildren parent)
        {
            IEnumerable <PickleStep> backgroundSteps = new List <PickleStep>(parentBackgroundSteps);

            foreach (var child in parent.Children)
            {
                if (child is Background)
                {
                    backgroundSteps = backgroundSteps.Concat(PickleSteps((Background)child));
                }
                else if (child is Rule)
                {
                    Build(pickles, language, tags, backgroundSteps, (Rule)child);
                }
                else
                {
                    var scenario = (Scenario)child;
                    if (!scenario.Examples.Any())
                    {
                        CompileScenario(pickles, backgroundSteps, scenario, tags, language);
                    }
                    else
                    {
                        CompileScenarioOutline(pickles, backgroundSteps, scenario, tags, language);
                    }
                }
            }
        }
Пример #15
0
 public static IEnumerable <StepsContainer> StepsContainers(this IHasChildren container)
 => container.Children.OfType <StepsContainer>();
Пример #16
0
 public static IEnumerable <Scenario> ScenarioDefinitions(this IHasChildren container)
 => container.Children.OfType <Scenario>();
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualTreeGridItem"/> class.
 /// </summary>
 /// <param name="data">The data.</param>
 public VirtualTreeGridItem(IHasChildren data)
 {
     category    = new VirtualTreeGridCategory(true);
     kind        = ModelKind.Root;
     DisplayName = Name = data.Name;
 }
Пример #18
0
 public static IEnumerable <Scenario> FlattenScenarioDefinitions(this IHasChildren featureOrRule)
 => featureOrRule.FlattenStepsContainers().OfType <Scenario>();