//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()); } }
private bool Matches(IViewModel parent, PathIterator nextStep) { if (!nextStep.HasStep) { return(false); } if (!(parent.Descriptor is TDescriptor)) { return(false); } TDescriptor descriptor = (TDescriptor)parent.Descriptor; IVMPropertyDescriptor expectedProperty = _propertySelector.GetProperty(descriptor); if (nextStep.IsProperty) { return(nextStep.Property == expectedProperty); } object expectedPropertyValue = parent.Kernel.GetValue(expectedProperty); if (nextStep.IsViewModel) { return(nextStep.ViewModel == expectedPropertyValue); } if (nextStep.IsCollection) { return(nextStep.Collection == expectedPropertyValue); } throw new NotSupportedException(); }
private bool Matches(IViewModel parent, PathIterator nextStep) { if (!nextStep.HasStep) { return(false); } if (!(parent.Descriptor is TDescriptor)) { return(false); } TDescriptor descriptor = (TDescriptor)parent.Descriptor; IVMPropertyDescriptor expectedProperty = _propertySelector.GetProperty(descriptor); if (nextStep.IsProperty) { return(nextStep.Property == expectedProperty); } if (!parent.Kernel.IsLoaded(expectedProperty)) { return(false); } object expectedPropertyValue = parent.Kernel.GetValue(expectedProperty); if (nextStep.IsViewModel) { if (nextStep.ViewModel == expectedPropertyValue) { return(true); } else { if (expectedPropertyValue is IVMCollection) { var parentCollection = (IVMCollection)expectedPropertyValue; return(nextStep .ViewModel .Kernel .OwnerCollections .Contains(parentCollection)); } else { return(false); } } } if (nextStep.IsCollection) { return(false); } throw new NotSupportedException(); }
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()); }
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()); } }
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()); }
private bool Matches(IViewModel parent, PathIterator nextStep) { if (!nextStep.HasStep || !(parent.Descriptor is TDescriptor)) { return(false); } if (nextStep.Property != null && !parent.Descriptor.Properties.Contains(nextStep.Property)) { throw new ArgumentException(ExceptionTexts.PropertyIsNotContainedByParentDescriptor); } return(true); }
public override PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step) { var match = _innerStep.Matches(definitionSteps, step); if (match.Success) { return(match); } else { return(definitionSteps.MatchesNext(step)); } }
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)); }
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 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()); } }
private static bool CollectionIsFollowedByItemViewModel(PathIterator step) { if (!step.IsCollection) { return(false); } IVMCollection collection = step.Collection; step.MoveNext(); if (!step.HasStep || !step.IsViewModel) { return(false); } IViewModel potentialItem = step.ViewModel; return(potentialItem.Kernel.OwnerCollections.Any(x => x.Equals(collection))); }
public abstract PathMatch Matches(PathDefinitionIterator definitionSteps, PathIterator step);