Exemplo n.º 1
0
        //public PropertyStep(
        //   Func<TDescriptor, IVMPropertyDescriptor> propertySelector,
        //   Type propertyHint
        //) {
        //   Check.NotNull(propertySelector, nameof(propertySelector));
        //   _propertySelector = propertySelector;
        //   _propertyNameHint = String.Format("IVMPropertyDescriptor<{0}>", TypeService.GetFriendlyName(propertyHint));
        //}

        public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step)
        {
            if (!step.HasStep || step.IsCollection || step.IsProperty)
            {
                return(PathMatch.Fail());
            }

            PathIterator parentStep = step;

            step.MoveNext();

            if (!step.HasStep)
            {
                return(PathMatch.Fail());
            }

            bool currentStepMatches = Matches(parentStep.ViewModel, step);

            if (currentStepMatches)
            {
                PathMatch result     = PathMatch.Succeed(length: 1);
                PathMatch nextResult = definitionSteps.MatchesNext(step);

                return(PathMatch.Combine(result, nextResult));
            }
            else
            {
                return(PathMatch.Fail());
            }
        }
Exemplo n.º 2
0
        public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step)
        {
            if (!step.HasStep || step.IsCollection || step.IsProperty)
            {
                return(PathMatch.Fail());
            }
            int          pathLength = 0;
            PathIterator parentStep = step;

            step.MoveNext();
            pathLength++;

            bool currentStepMatches = Matches(parentStep.ViewModel, step);

            if (currentStepMatches)
            {
                while (step.HasStep)
                {
                    step.MoveNext();
                    pathLength++;
                }

                return(PathMatch.Succeed(length: pathLength));
            }
            else
            {
                return(PathMatch.Fail());
            }
        }
Exemplo n.º 3
0
        public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step)
        {
            if (!step.HasStep || !step.IsCollection)
            {
                return(PathMatch.Fail());
            }

            IVMCollection parentCollection = step.Collection;

            step.MoveNext();

            if (!step.HasStep || !step.IsProperty)
            {
                return(PathMatch.Fail());
            }

            if (!(parentCollection.GetItemDescriptor() is TDescriptor))
            {
                return(PathMatch.Fail());
            }

            var itemDescriptor   = parentCollection.GetItemDescriptor();
            var expectedProperty = _propertySelector.GetProperty(itemDescriptor);

            if (expectedProperty == step.Property)
            {
                PathMatch result     = PathMatch.Succeed(length: 1);
                PathMatch nextResult = definitionSteps.MatchesNext(step);

                return(PathMatch.Combine(result, nextResult));
            }

            return(PathMatch.Fail());
        }
Exemplo n.º 4
0
 public override IViewModel[] GetDescendants(
     PathDefinitionIterator definitionSteps,
     IViewModel rootVM,
     bool onlyLoaded
     )
 {
     throw new NotSupportedException();
 }
Exemplo n.º 5
0
 public override IViewModel[] GetDescendants(
     PathDefinitionIterator definitionSteps,
     IViewModel rootVM,
     bool onlyLoaded
     )
 {
     return(new IViewModel[] { rootVM });
 }
Exemplo n.º 6
0
 public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step)
 {
     foreach (var orStep in _steps)
     {
         var match = orStep.Matches(definitionSteps, step);
         if (match.Success)
         {
             return(match);
         }
     }
     return(PathMatch.Fail());
 }
Exemplo n.º 7
0
        public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step)
        {
            var match = _innerStep.Matches(definitionSteps, step);

            if (match.Success)
            {
                return(match);
            }
            else
            {
                return(definitionSteps.MatchesNext(step));
            }
        }
Exemplo n.º 8
0
        public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step)
        {
            int matchedSteps = 0;

            if (step.HasStep)
            {
                step.MoveNext();
                matchedSteps++;
            }

            return(step.HasStep ?
                   PathMatch.Fail() :
                   PathMatch.Succeed(length: matchedSteps));
        }
Exemplo n.º 9
0
        public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step)
        {
            if (!step.HasStep || !step.IsViewModel)
            {
                return(PathMatch.Fail());
            }

            IViewModel parentViewModel = step.ViewModel;

            step.MoveNext();

            if (!step.HasStep || !step.IsCollection)
            {
                return(PathMatch.Fail());
            }

            if (!(parentViewModel.Descriptor is TDescriptor))
            {
                return(PathMatch.Fail());
            }

            var descriptor = (TDescriptor)parentViewModel.Descriptor;

            var collectionProperty = (IVMPropertyDescriptor)_propertySelector.GetProperty(descriptor); // HACK ATTACK

            if (!parentViewModel.Kernel.IsLoaded(collectionProperty))
            {
                return(PathMatch.Fail());
            }

            var expectedCollection = parentViewModel.Kernel.GetValue(collectionProperty);

            if (step.Collection == expectedCollection)
            {
                PathMatch result     = PathMatch.Succeed(length: 1);
                PathMatch nextResult = definitionSteps.MatchesNext(step);

                return(PathMatch.Combine(result, nextResult));
            }
            else
            {
                return(PathMatch.Fail());
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public IViewModel[] GetLoadedDescendants(IViewModel rootVM)
        {
            var it = new PathDefinitionIterator(_steps);

            return(it.GetDescendantNext(rootVM, onlyLoaded: true));
        }
Exemplo n.º 12
0
        public PathMatch Matches(Path path)
        {
            var it = new PathDefinitionIterator(_steps);

            return(it.MatchesNext(path.GetIterator()));
        }
Exemplo n.º 13
0
 public abstract IViewModel[] GetDescendants(PathDefinitionIterator definitionSteps, IViewModel rootVM, bool onlyLoaded);
Exemplo n.º 14
0
 public abstract PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step);