Constructor in generated code
No edit summary
No edit summary
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Different operation kinds of methods:
<message>Write the content here to display this box</message>
There are different kinds of operation methods:
[[File:2021-10-14 18h31 05.png|none|thumb]]
[[File:2021-10-14 18h31 05.png|none|thumb]]
[[File:2021-10-14 18h27 52.png|none|thumb|692x692px]]
[[File:2021-10-14 18h27 52.png|none|thumb|692x692px]]
To create a constructor you first add a normal method, then change the operationKind to constructor.
To create a constructor, first, add a normal method, then change the <code><span class="col-black">'''operationKind'''</span></code> to constructor.


In generated code you will get this:
In generated code, you will get this:
  public partial class Class1
  public partial class Class1
  {
  {
Line 13: Line 14:
  }
  }


Normally when doing a constructor for "live" objects you will want to send in IEcoServiceProvider and call the main constructor we provide like this:
Normally, when doing a constructor for "live" objects, you will want to send in IEcoServiceProvider and call the main constructor we provide like this:
  public Class1(IEcoServiceProvider serviceProvider, Class2 aClass2): this(serviceProvider)
  public Class1(IEcoServiceProvider serviceProvider, Class2 aClass2): this(serviceProvider)
  {
  {
  }
  }
[[Category:MDriven Framework]]
[[Category:MDriven Framework]]
 
=== When not using code - only action language ===
When not using code - only action language (EAL) we do not allow for constructors being implemented in the body property of the method. You can however set OperationKind:Static and go like this:
SimulatedConstructor(input1:String; input2:String):Class1
And in the body:
 
let ret=Class1.Create in(
ret.Attribute1:=input1;
ret.Attribute2:=input2;
ret )
 
All in all this will serve the same effect as a constructor - when you need to set provided parameters or create structures in one go call it with:
Class1.SimulatedConstructor('a','b')
{{Edited|July|12|2025}}

Latest revision as of 05:08, 23 April 2025

This page was created by Hans.karlsen@mdriven.net on 2021-10-14. Last edited by Stephanie@mdriven.net on 2025-04-23.

There are different kinds of operation methods:

2021-10-14 18h31 05.png
2021-10-14 18h27 52.png

To create a constructor, first, add a normal method, then change the operationKind to constructor.

In generated code, you will get this:

public partial class Class1
{
  [UmlElement(Id = "c8111515-b7a5-4b9b-87f9-4a19261c8bd8")]
  public Class1(Class2 aClass2)
  {
  }
}

Normally, when doing a constructor for "live" objects, you will want to send in IEcoServiceProvider and call the main constructor we provide like this:

public Class1(IEcoServiceProvider serviceProvider, Class2 aClass2): this(serviceProvider)
{
}

When not using code - only action language

When not using code - only action language (EAL) we do not allow for constructors being implemented in the body property of the method. You can however set OperationKind:Static and go like this:

SimulatedConstructor(input1:String; input2:String):Class1

And in the body:

let ret=Class1.Create in(
ret.Attribute1:=input1;
ret.Attribute2:=input2;
ret )

All in all this will serve the same effect as a constructor - when you need to set provided parameters or create structures in one go call it with:

Class1.SimulatedConstructor('a','b')