/// <summary> /// Initializes a new instance. /// </summary> /// <param name="requiredPort">The reference to the required port that should be bound.</param> /// <param name="providedPort">The reference to the provided port that should be bound.</param> public PortBinding(PortReference requiredPort, PortReference providedPort) { Requires.NotNull(requiredPort, nameof(requiredPort)); Requires.NotNull(providedPort, nameof(providedPort)); RequiredPort = requiredPort; ProvidedPort = providedPort; var metadataAttribute = BindingMetadataAttribute.Get(RequiredPort.GetMethod()); metadataAttribute.BindingField.SetValue(requiredPort.TargetObject, this); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="requiredPort">The reference to the required port that should be bound.</param> /// <param name="providedPort">The reference to the provided port that should be bound.</param> public PortBinding(PortReference requiredPort, PortReference providedPort) { Requires.NotNull(requiredPort, nameof(requiredPort)); Requires.NotNull(providedPort, nameof(providedPort)); RequiredPort = requiredPort; ProvidedPort = providedPort; var metadataAttribute = BindingMetadataAttribute.Get(RequiredPort.GetMethod()); metadataAttribute.BindingField.SetValue(requiredPort.TargetObject, this); }
protected override void Check() { var d = new D { A = 7, C = 3 }; var r = new PortReference(d, typeof(D), "M", new[] { typeof(bool), typeof(int) }, typeof(bool), false); var p = new PortReference(d, typeof(D), "Q", new[] { typeof(bool), typeof(int) }, typeof(bool), true); d.B = new PortBinding(r, p); var m = InitializeModel(d); Create(m); StateFormulas.ShouldBeEmpty(); RootComponents.Length.ShouldBe(1); StateSlotCount.ShouldBe(2); var root = RootComponents[0]; root.ShouldBeOfType<D>(); r = ((D)root).B.RequiredPort; p = ((D)root).B.ProvidedPort; r.TargetObject.ShouldBe(root); r.DeclaringType.ShouldBe(typeof(D)); r.PortName.ShouldBe("M"); r.ArgumentTypes.ShouldBe(new[] { typeof(bool), typeof(int) }); r.ReturnType.ShouldBe(typeof(bool)); r.IsVirtualCall.ShouldBe(false); p.TargetObject.ShouldBe(root); p.DeclaringType.ShouldBe(typeof(D)); p.PortName.ShouldBe("Q"); p.ArgumentTypes.ShouldBe(new[] { typeof(bool), typeof(int) }); p.ReturnType.ShouldBe(typeof(bool)); p.IsVirtualCall.ShouldBe(true); ((D)root).A.ShouldBe(7); ((D)root).C.ShouldBe(3); }