public void Dispatch_ShouldSupportGenericMethods() { var mockChild = new Mock <IGeneric>(MockBehavior.Strict); IGeneric parent = null; mockChild .SetupGet(i => i.Parent) .Returns(() => parent); #pragma warning disable CS0618 // Type or member is obsolete mockChild .SetupSet(i => i.Parent) #pragma warning restore CS0618 .Callback(val => parent = val); mockChild.Setup(i => i.Foo(1)); var root = new GenericComposite(); root.Children.Add(mockChild.Object); root.Foo(1); mockChild.Verify(i => i.Foo(1), Times.Once); }
public GenericComposite <T> AddChild(T element) { var n = new GenericComposite <T>(element, this); children.Add(n); return(n); }
public GenericComposite <T> AddSibling(T element) { if (this.parent == null) { throw new System.Exception("Trying to add sibling to root of tree isnt supported"); } var n = new GenericComposite <T>(element, this.parent); this.parent.children.Add(n); return(this); }
public void Create12345Tree() { GenericComposite <int> composite = new GenericComposite <int>(1); composite .AddChild(2) .AddChild(4).AddSibling(5); composite .AddChild(3); _composite = composite; }
/// <summary> Returns the Primitive object at the given location in the given field. /// It is intended that the given type be at the field level, although extra components /// will be added blindly if, for example, you provide a primitive subcomponent instead /// and specify component or subcomponent > 1. /// </summary> public static IPrimitive GetPrimitive(IType type, int component, int subcomponent) { if (type == null) { throw new ArgumentNullException(nameof(type), "type may not be null"); } if (component < 1) { throw new ArgumentOutOfRangeException( nameof(component), "component must not be 1 or more (note that this parameter is 1-indexed, not 0-indexed)"); } if (subcomponent < 1) { throw new ArgumentOutOfRangeException( nameof(subcomponent), "subcomponent must not be 1 or more (note that this parameter is 1-indexed, not 0-indexed)"); } var comp = GetComponent(type, component); if (type is Varies && comp is GenericPrimitive && subcomponent > 1) { try { var varies = (Varies)type; var comp2 = new GenericComposite(type.Message); varies.Data = comp2; comp = GetComponent(type, component); } catch (DataTypeException ex) { var message = $"Unexpected exception copying data to generic composite. This is probably a bug within NHapi. {ex.Message}"; log.Error(message); throw new ApplicationException(message, ex); } } var sub = GetComponent(comp, subcomponent); return(GetPrimitive(sub)); }
protected virtual void SetUpStack(GenericComposite <T> root) { if (root.children.Count > 0) { for (int i = 0; i < root.children.Count; i++) { SetUpStack(root.children[i]); } stack.Add(root); } else { stack.Add(root); } }
protected override void SetUpStack(GenericComposite <T> root) { if (root.children.Count == 0) { stack.Add(root); return; } for (int i = 0; i < root.children.Count; i++) { SetUpStack(root.children[i]); if (!stack.Contains(root)) { stack.Add(root); } } }
public void BindingWithId() { Container.Bind <int>().WithId("5").FromInstance(5); GenericComposite <int> composite = new GenericComposite <int>(Container.ResolveId <int>("5")); composite.AddChild(Container.ResolveId <int>("5")); foreach (var element in composite) { Debug.Log(element.element); } LogAssert.Expect(LogType.Log, "5"); LogAssert.Expect(LogType.Log, "5"); }
public virtual bool MoveNext() { if (stack.Count == 0) { return(false); } current = stack[0]; stack.RemoveAt(0); if (current.children.Count > 0) { stack.AddRange(current.children); } return(true); }
internal Medication buildMedication(RDT rdt) { Medication med = new Medication(); med.OrderId = HL7Helper.getString(rdt, 13, 0); med.Refills = HL7Helper.getString(rdt, 11, 0); med.Quantity = HL7Helper.getString(rdt, 9, 0); med.DaysSupply = HL7Helper.getString(rdt, 10, 0); med.IssueDate = HL7Helper.getString(rdt, 4, 0); med.LastFillDate = HL7Helper.getString(rdt, 5, 0); med.StartDate = HL7Helper.getString(rdt, 6, 0); med.ExpirationDate = HL7Helper.getString(rdt, 7, 0); med.RxNumber = HL7Helper.getString(rdt, 1, 0); med.Id = HL7Helper.getString(rdt, 2, 0); med.Provider = new Author(); NHapi.Base.Model.IType provider = ((Varies)rdt.GetField(12, 0)).Data; if (provider is GenericComposite) { GenericComposite gc = (GenericComposite)provider; NHapi.Base.Model.IType[] components = gc.Components; med.Provider.Id = ((Varies)components[0]).Data.ToString(); med.Provider.Name = ((Varies)components[1]).Data.ToString() + ", " + ((Varies)components[2]).Data.ToString(); } else { med.Provider.Id = provider.ToString(); } med.Name = HL7Helper.getString(rdt, 3, 0); med.Sig = HL7Helper.getString(rdt, 20, 0); med.Detail = HL7Helper.getString(rdt, 19, 0); med.Status = HL7Helper.getString(rdt, 8, 0); return(med); }
public GenericComposite(T element, GenericComposite <T> parent = null) { this.parent = parent; this.element = element; children = new List <GenericComposite <T> >(); }
public PostOrderCompositeIterator(GenericComposite <T> root) { this.root = root; SetUpStack(root); }
public PreOrderCompositeIterator(GenericComposite <T> root) : base(root) { }
public CompositeIterator(GenericComposite <T> root) { stack.Add(root); }