Beispiel #1
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());
        }
Beispiel #2
0
        private bool Matches(IVMCollection collection, PathIterator nextStep)
        {
            bool canMatchAgainstItemDescriptor = nextStep.IsProperty;

            if (!canMatchAgainstItemDescriptor)
            {
                return(false);
            }

            if (!(collection.GetItemDescriptor() is TDescriptor))
            {
                return(false);
            }

            TDescriptor itemDescriptor = (TDescriptor)collection.GetItemDescriptor();

            return(_propertySelector.GetProperty(itemDescriptor) == nextStep.Property);
        }
 public IValidatorInvocationBuilder Targeting <TDescriptor>(
     IVMCollectionExpression <IViewModel <TDescriptor> > target,
     Func <TDescriptor, IVMPropertyDescriptor> targetPropertySelector
     ) where TDescriptor : IVMDescriptor
 {
     _targetCollection = (IVMCollection)target;
     _targetProperty   = targetPropertySelector((TDescriptor)_targetCollection.GetItemDescriptor());
     return(this);
 }