Using framework-specific types

In the previous part, you generated a C# model from a Yellicode model. A Yellicode model is (like any standard UML model) language- and platform independent. This means that it only contains a few, basic, types (boolean, integer, object, real and string).

Only being able to use these types would be very limiting if we want to target our model at .NET or any other platform. This is why UML has a concept named 'Profiles', which is also supported by Yellicode.

Here's the official definition:

"A profile defines limited extensions to a reference metamodel with the purpose of adapting the metamodel to a specific platform or domain."

In this part of the tutorial, you are going to learn how to apply a Profile (specifically, the Yellicode .NET Profile) to your model, so that you use .NET types to your model too.

Importing the profile

Like any other Yellicode extension, a profile can also be shared as an NPM package. All you need to know before importing a profile into Yellicode Modeler, is the package name. The package name of the Yellicode .NET Profile is @yellicode/dotnet-profile

Use the following steps to import the profile into your model:

  1. In the REFERENCES tab in the project explorer, click the '+' icon and choose 'NPM Package'.
  2. Enter @yellicode/dotnet-profile and wait for the package to install.

Using the profile

Before using a profile in your model, you first need to apply it to a package (or to the model itself, which is also a package). Since we have no nested packages, let's apply it to the entire model.

  1. Right-click the IssueManager package.
  2. Choose 'Apply Profile(s)'.
  3. In the following dialog, check .NET System and confirm.

Now we are going to change the type of the Bug.FixedInVersion property to Decimal.

  1. Open the attribute editor for FixedInVersion and find the 'Type' field.
  2. In the Type dropdown, choose Decimal (.NET System).
  3. Leave the dropdown and save your changes.

Now, if the code generator isn't still running, restart it and wait for a second or two.

yellicode --watch

If all went well, you should now see an updated Bug class in the output.

/// <summary>
/// A bug is something that just doesn't work as expected or just goes painfully wrong.
/// </summary>
public class Bug : Issue
{
    /// <summary>
    /// The version of the application in which the bug was discovered.
    /// </summary>
    public string DiscoveredInversion { get; set; }

    /// <summary>
    /// The version of the application in which the bug was fixed.
    /// </summary>
    public Decimal FixedInVersion { get; set; }
}

While Yellicode Modeler installed the .NET profile package, it also added the @yellicode/dotnet-profile dependency to the current directory's package.json file. Due to how NPM works, the availability of a package.json is required when you import NPM packages into Yellicode Modeler. If your model would be in a different directory, a new package.json file would have been created automatically by Yellicode Modeler.

Continue to Part IV - Adding custom meta data »