private void AnalyzeLink(LinkNode linkItem) { var v = new FindRequirementsVisitor(_strategy); Expression @override; if (linkItem.Instance is LambdaExpression) { @override = v.Visit((LambdaExpression) linkItem.Instance); } else if (linkItem.Instance is Binding) { @override = v.Visit(((Binding) linkItem.Instance).BindingLambda); } else { throw new Exception("bad"); } if (v.Modified) { linkItem.Expression = (LambdaExpression)@override; } foreach (var x in v.MemberRequirements) { ApplyMemberRequirement(x); } foreach (var x in v.MetadataRequirements) { ApplyMetadataRequirement(x); } foreach (var x in v.Constants) { // add the constant as a dependent of this expression RegisterItem(x, linkItem); } }
private RenderNode RegisterItem(object instance, RenderNode dependent) { if (instance == null) return null; RenderNode result; if (!_items.TryGetValue(instance, out result)) { IEnumerable<object> elements; switch (_strategy.ClassifyInstance(instance, out elements)) { case InstanceType.Object: result = new ObjectOrValueNode(instance, _nextId++, false); break; case InstanceType.Value: result = new ObjectOrValueNode(instance, _nextId++, true); break; case InstanceType.Link: result = new LinkNode(instance, _nextId++); break; case InstanceType.Collection: var collection = new CollectionNode(instance, _nextId++); result = collection; collection.Elements.AddRange(elements.Select(x => RegisterItem(x, result))); break; } if (result != null) { _items[instance] = result; _newItems.Enqueue(result); } } if (result != null && dependent != null) // TODO: consider requiring non null { result.Dependents.Add(dependent); dependent.Dependencies.Add(result); } return result; }
protected string RenderValue(LinkNode node) { var status = _renderSchedule.GetStatus(node); status.HasEmitted = true; var expression = node.Expression; return PortAsLambda(expression).PortedText; }