Previous: , Up: Integrating code in other languages   [Contents]

3.8.2 Foreign components in C#

The interface iLED is provided by the LED component, which is a foreign component and therefore not generated from your Dezyne models. The generated AlarmSystem System component does refer to an object of type LED, so you will have to make this object yourself. Take note that this object should not be contained in a namespace; the generated System refers directly to LED.

A prototype of an LED class that complies to the ILED interface is as follows:

class LED {
  public ILED iLed;

  public LED(dzn.Locator locator, String name = "", dzn.Meta parent = null) {
    iLed = new ILED();

    iLed.inport.setGreen = this.setGreen;
    iLed.inport.setYellow = this.setYellow;
    iLed.inport.setRed = this.setRed;
    iLed.inport.turnOff = this.turnOff;

  public void setGreen() {}
  public void setYellow() {}
  public void setRed() {}
  public void turnOff() {}

The LED class has a public member named iLed of type ILED; the name of this member variable has to be the same as the name of the provided interface of the respective component in your Dezyne model. Then, in the constructor the events of ILED that are to be implemented are bound to the implementations within the LED class.