Exemple #1
0
        public override IViewModel[] GetDescendants(
            PathDefinitionIterator definitionSteps,
            IViewModel rootVM,
            bool onlyLoaded
            )
        {
            var property = _propertySelector.GetProperty(rootVM.Descriptor);

            if (onlyLoaded && !rootVM.Kernel.IsLoaded(property))
            {
                return(new IViewModel[0]);
            }

            var instance = rootVM.Kernel.GetValue(property);

            if (PropertyTypeHelper.IsViewModelCollection(property.PropertyType))
            {
                if (instance == null)
                {
                    return(new IViewModel[0]);
                }

                var collection = (IVMCollection)instance;
                return(((IVMCollection)instance)
                       .Cast <IViewModel>()
                       .SelectMany(x => definitionSteps.GetDescendantNext(x, onlyLoaded))
                       .ToArray());
            }
            else if (PropertyTypeHelper.IsViewModel(property.PropertyType))
            {
                if (instance == null)
                {
                    return(new IViewModel[0]);
                }

                return(definitionSteps.GetDescendantNext((IViewModel)instance, onlyLoaded));
            }

            throw new NotSupportedException(ExceptionTexts.GetDescaedantsWrongPropertyStepType);
        }
Exemple #2
0
        public IViewModel[] GetLoadedDescendants(IViewModel rootVM)
        {
            var it = new PathDefinitionIterator(_steps);

            return(it.GetDescendantNext(rootVM, onlyLoaded: true));
        }