private IExpressionNode VisitExpression(IExpressionNode node) { var nodes = new List <IExpressionNode>(); string memberName = node.TryGetMemberName(true, true, nodes); if (memberName == null) { _isMulti = true; return(node); } if (nodes[0] is ResourceExpressionNode) { return(GetResourceMember(node, memberName, nodes)); } IBindingPath path = BindingServiceProvider.BindingPathFactory(memberName); if (path.IsEmpty) { return(GetOrAddBindingMember(memberName, (s, i) => new BindingMemberExpressionNode(memberName, s, i))); } string firstMember = path.Parts[0]; if (_lamdaParameters.Contains(firstMember)) { return(node); } return(GetOrAddBindingMember(memberName, (s, i) => new BindingMemberExpressionNode(memberName, s, i))); }
public BindingContextSource(object source, IBindingMemberInfo member) { _member = member; _observer = BindingServiceProvider .ObserverProvider .Observe(source, BindingServiceProvider.BindingPathFactory(member.Path), true, DataContext.Empty); _observer.ValueChanged += ObserverOnValueChanged; }
private IExpressionNode GetResourceMember(IExpressionNode node, string memberName, IList <IExpressionNode> nodes) { IExpressionNode staticValue; if (_staticNodes.TryGetValue(node, out staticValue)) { return(staticValue); } IBindingPath path = BindingServiceProvider.BindingPathFactory(memberName); string firstMember = path.Parts[0]; Type type = BindingServiceProvider.ResourceResolver.ResolveType(firstMember, Context, false); var resourceMember = (ResourceExpressionNode)nodes[0]; if (resourceMember.Dynamic && type == null) { memberName = BindingExtensions.MergePath(path.Parts.Skip(1).ToArray()); return(GetOrAddBindingMember("$" + path.Path, (s, i) => new BindingMemberExpressionNode(firstMember, memberName, s, i))); } bool dynamicMember = false; IExpressionNode firstMemberNode = nodes[1]; if (!_staticNodes.TryGetValue(firstMemberNode, out staticValue)) { if (type == null) { var value = BindingServiceProvider .ResourceResolver .ResolveObject(firstMember, Context, true) .Value; var dynamicObject = value as IDynamicObject; if (dynamicObject == null || path.Parts.Count <= 1) { staticValue = new ConstantExpressionNode(value); } else { staticValue = new ConstantExpressionNode(dynamicObject.GetMember(path.Parts[1], Empty.Array <object>())); dynamicMember = true; } } else { staticValue = new ConstantExpressionNode(type, typeof(Type)); } _staticNodes[firstMemberNode] = staticValue; if (dynamicMember) { _staticNodes[nodes[2]] = staticValue; } } if (firstMemberNode == node || (dynamicMember && node == nodes[2])) { return(staticValue); } return(node); }