Fork me on GitHub
ecorenetto - .NET library for reading Ecore models

Getting Started


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.

Ecore Hierarchy

Ecore Components

Ecore relationships, attributes and operations

Ecore Relationships, attributes and operations