private string ConvertToJsonKeyPath(Expression <Func <TDto, object> > expression) { var visitor = new PathVisitor(_resourceTypeRegistry); visitor.Visit(expression); return(visitor.Path); }
public static string Property(Expression <Func <object> > property) { var pathVisitor = new PathVisitor(); pathVisitor.Visit(property); return(string.Join(".", pathVisitor.Properties.Select(x => x.Name))); }
public void CanTryVisitAtPath(string path, bool expected) { var container = new PropertyPathTestContainer(); var visitor = new PathVisitor(); var changeTracker = new ChangeTracker(); var propertyPath = new PropertyPath(path); Assert.That(PropertyContainer.TryVisitAtPath(ref container, propertyPath, visitor, ref changeTracker), Is.EqualTo(expected)); if (expected) { var lastPart = propertyPath[propertyPath.PartsCount - 1]; var name = lastPart.IsListItem ? $"[{lastPart.Index}]" : lastPart.Name; Assert.That(visitor.Last == name); } }
public void CanVisitAtPath(string path, bool expected) { var container = new PropertyPathTestContainer(); var visitor = new PathVisitor(); var changeTracker = new ChangeTracker(); var propertyPath = new PropertyPath(path); if (expected) { PropertyContainer.VisitAtPath(ref container, propertyPath, visitor, ref changeTracker); var lastPart = propertyPath[propertyPath.PartsCount - 1]; var name = lastPart.IsListItem ? $"[{lastPart.Index}]" : lastPart.Name; Assert.That(visitor.Last == name); } else { Assert.Throws <ArgumentException>(() => PropertyContainer.VisitAtPath(ref container, propertyPath, visitor, ref changeTracker)); } }
/// <summary> /// 返回表示式对应的path /// </summary> /// <param name="pathSelector">path选择器</param> /// <returns></returns> private string GetExpressionPath(LambdaExpression pathSelector) { var visitor = new PathVisitor(pathSelector, this.GetMemberName); return(visitor.ToString()); }
public static string Property(Expression<Func<object>> property) { var pathVisitor = new PathVisitor(); pathVisitor.Visit(property); return string.Join(".", pathVisitor.Properties.Select(x => x.Name)); }