Skip to content

Getting Started

samatstarion edited this page Sep 8, 2024 · 4 revisions

Getting Started

NOTE: The documentation on how to use EcoreNetto.Tools can be found here ECoreNetto.Tools

Introduction

Ecore is a meta-model used to represent models in the Eclipse Modelling Framework (EMF). A typical use case is that an Ecore meta-model is created to define the domain model of an application. EMF is a powerful framework and code generation facility for building Java applications based on simple model definitions EcoreNetto does not aim to be a port of EMF, it aims at bridging the gap to the .NET world to facilitate code generation of C# class libraries based on an Ecore meta-model using the .NET code available tooling and libraries. With EcoreNetto an Ecore meta-model can be read and the content can be navigated from code. EcoreNetto does not peform any code generation itself. We do not have a preconception on how this should be done but the following technologies can be used:

Loading a Model

An Ecore meta-model can be distributed accross different files. This usualy happens when a meta-model is created in a modular way and one meta-model uses a type or class that has been defined in another meta-model. In Ecore a file is actualy called a Resource. Multiple resoures can be combined in one ResourceSet. The ResourceSet class has a factory method to create a Resource using a URI. The created Resource exposes the Load method to start loading the content of the Resource. The result of Load is an instance of EPackage. This is the root package of the Resource. If in the loaded Resource another Resource is referenced, ecorrenetto will start loading that Resource as well. The following code snippet demonstrates how to load a Resource:

public void Load()
{
    var path = "some-file-path.ecore";
    var uri = new Uri(path);
    var resourceSet = new ResourceSet();
    var resource = ResourceSet.CreateResource(uri);
    var root = resource.Load(null);
}

Working with a Model

In the previous section a Resource was loaded and the result is a reference to the root EPackage of that Resource. Notice that the classes in the ecorenetto library following the naming convention in Ecore. Each class starts with the capital letter E to make it clear these are Ecore concepts.

The followingi images present the Ecore Components and the Ecore Relationships, attributes and operations:

Ecore Components Ecore Relationships, attributes and operations

Example Project - SysML2.NET

The SysML2.NET solution makes use of ECore, EcoreNetto and Handlebars.NET to generate code. Have a look at the SysML2.NET.CodeGenerator project to get inspired.