public static BindingHandle CreateBinding <A, B>(BindPoint source, Arrow <A, B> arrow, BindPoint destination) { /* * Creates a one-to-one binding from a source, an arrow and a destination. Infers * whether it should be bidirectional from the type of the supplied arrow. */ if (LinkWouldCauseConflict(source, destination)) { throw new BindingConflictException(); } Binding <A, B> result; if (arrow is InvertibleArrow <A, B> ) { result = new TwoWayBinding <A, B>(source, (InvertibleArrow <A, B>)arrow, destination); UpdateBindingGraphBothWays(source, destination); } else { result = new Binding <A, B>(source, arrow, destination); UpdateBindingGraph(source, destination); } BindingHandle handle = new BindingHandle(result); bindings.Add(handle, result); return(handle); }
public override bool Equals(Object o) { if (o is BindingHandle) { BindingHandle otherBinding = (BindingHandle)o; return(Equals(id, otherBinding.id)); } else { return(false); } }
public static void Unbind(BindingHandle handle) { /* * Removes the binding associated with the given handle by calling its Unbind method * to unsubscribe it from events, removing it from the bindings dictionary and removing * it from the binding graph. */ IBinding binding = bindings[handle]; binding.Unbind(); bindings.Remove(handle); bindGraph.RemoveBindings(binding.GetSources().ToArray(), binding.GetDestinations().ToArray()); }
public static BindingHandle CreateBinding <A, B>(BindPoint[] sources, Arrow <A, B> arrow, BindPoint[] destinations) { /* * Creates a many-to-many binding from a list of sources, an arrow (on tuples) and a * list of destinations. Infers whether it should be bidirectional from the type of the * supplied arrow. * * NOTE: Syntax for this constructor is simplified by the helper functions below, * leading to: * * CreateBinding(Sources(BindPoint(obj, var), BindPoint(obj', var')), arrow, * Destinations(BindPoint(obj'', var''))) */ if (MultiLinkWouldCauseConflict(sources, destinations)) { throw new BindingConflictException(); } if (!ArgumentCountsCorrectForArrow(sources.Count(), destinations.Count(), arrow)) { throw new BindingEndpointCountException(); } MultiBinding <A, B> result; if (arrow is InvertibleArrow <A, B> ) { result = new TwoWayMultiBinding <A, B>(sources.ToList(), (InvertibleArrow <A, B>)arrow, destinations.ToList()); UpdateBindingGraphBothWays(sources, destinations); } else { result = new MultiBinding <A, B>(sources.ToList(), arrow, destinations.ToList()); UpdateBindingGraph(sources, destinations); } BindingHandle handle = new BindingHandle(result); bindings.Add(handle, result); return(handle); }