Modelio C# Designer generation provides several features related to generation.
Commands available from a C# class.
List of commands:
C# attributes are defined through the C# property view of a Class, by choosing ‘C# Attribute’ value in the C# element field.
C# attribute property view.
This view defines all options available on the C# Attribute definition.
Indexers are modeled through a UML class with two operations, “get” and “set”, to which the <<CsIndexer>> stereotype is added. A class stereotyped <<CsIndexer>> will not be generated. It will simply be used to generate C# indexer get and set signatures and bodies.
To create an indexer, simply use the ‘Create C# Designer element’ contextual menu on a class:
Create C# Indexer command.
The following is a description of indexer accessors:
These functions help to resolve the indexer signature. Indexer signatures are as follows:
Indexer-visibilityindexer-returnType this[indexer-parameters] { ... }
C# events are modeled throught a UML signal to which the “CsEvent” stereotype is added. This signal must be a part of a class. Once a signal is stereotyped as an event, you can manage new values such as visibility (using the C# property view) and delegate association (using Signal UML properties tab’s Base field). An event must refer to a model’s delegate.
To create a C# event, simply use the ‘Create C# Designer element’ contextual menu on a class:
Create C# Event command.
Delegates can be operations issued from C# delegate containers (classes stereotyped “CsDelegateContainer”) or C# delegates (operations stereotyped “CsDelegate”). The related reference can be created through a drag and drop operation.
C# delegate containers (classes stereotyped “CsDelegateContainer”) are used as containers of C# delegate types (operations stereotyped “CsDelegate”). The generated delegates belong to the current parent element.
Stereotyping an operation “CsDelegate” will enable delegate signature and skip generation of all code notes attached to the operation.
To obtain the property declaration with simplified syntax, you must not define any associated code notes (CsGetCode/CsSetCode), as if you do, a normal property will be generated.
The generator will automatically apply the “private” modifier (by default) to the get or set accessor according to which access mode has been selected, as shown in the table below.
Access mode / Modifiers | None | Read | Write | ReadWrite |
---|---|---|---|---|
get | Error | Warning | CsPropertyVisibilityGet or private | Warning or Error |
set | Error | CsPropertyVisibilitySet or private | Warning | Warning or Error |
Example of automatically implemented properties
UML Model
C# Generated
1 using System;
2 using System.Diagnostics;
3 namespace ExtensionMethods
4 {
5 public class LightweightCustomer
6 {
7 #region TotalPurchases
8 public int TotalPurchases { get; set; }
9 #endregion
10
11 #region Name
12 public string Name { get; private set; } // read-only
13 #endregion
14
15 #region CustomerID
16 public int CustomerID { private get; set; } // write-only
17 #endregion
18 }
19 }
To define a method as being a partial method, simply check the “Partial” tick box in the C# property view. Modelio C# Designer will then position the new “partial” modifier just before the void keyword during code generation.
The generator will ignore the {CsPartial} tagged value if the method has a return parameter, one or more “out” parameters, or a virtual, abstract, override, new or sealed modifier. Furthermore, the visibility of the method must be private or default (implicitly private).
Example of using partial types and methods
UML model
C# generated
1 // Definition in file1.cs
2 using System;
3 using System.Diagnostics;
4
5 namespace Project.Definition
6 {
7 public partial class PartialClass
8 {
9 partial void PartialMethod();
10 }
11 }
12
13
14 // Implementation in file2.cs
15 using System;
16 using System.Diagnostics;
17 namespace Project.Implementation
18 {
19 public partial class PartialClass
20 {
21 public void PartialMethod()
22 {
23 // implementation code
24 }
25 }
26 }
27
Note 1: A partial method containing a “CsCode” or “CsReturned” note will generate the implementation part. The definition part will be produced if the partial method does not have these notes.
Note 2: A partial method declaration is made up of two parts: the definition and the implementation. It is up to the user to only create a single definition/implementation couple.
Be careful, Modelio C# Designer runs no tests on this.