Skip to content
samatstarion edited this page Oct 4, 2026 · 16 revisions

uml4net is a .NET implementation of the OMG UML specification. It is typically used to read a UML model from an XMI file, generate code on the basis of its content, and write the model back to XMI. A large part of the classes contained in the various projects are code generated using uml4net itself by parsing the Normative Machine Readable Documents provided with the spec:

Description URL
UML 2.5.1 Abstract Syntax Metamodel UML/20161101/UML.xmi
UML 2.5.1 Primitive Types UML/20161101/PrimitiveTypes.xmi
UML 2.5.1 Standard Profile UML/20161101/StandardProfile.xmi
UML 2.5.1 Diagram Interchange Metamodel UML/20161101/UMLDI.xmi

The uml4net solution contains the following libraries/packages:

  • uml4net: The core library/project that contains all the class definitions as they appear in the UML 2.5.1 specification.
  • uml4net.Extensions: A library/project that provides extension methods for the uml4net library/project.
  • uml4net.xmi: A library/project with a typed XMI reader and writer, to read a UML model from an XMI 2.5.1 document and write it back, also as Canonical XMI.
  • uml4net.xmi.Extensions.EnterpriseArchitect: An XMI reader extension to read Enterprise Architect XMI exports.
  • uml4net.HandleBars: A library/project that provides HandleBars helpers to support code generation.
  • uml4net.Reporting: A library/project that provides a number of report generators (html, xlsx, text) that generate documentation on the basis of the loaded UML model.
  • uml4net.Tools: A commandline application that is used to generate reports on the contents of a UML model. Find the documentation here.

Reading a UML model

Reading a UML model is straightforward and is done using the an IXmiReader. An instance of IXmiReader is created using the XmiReaderBuilder. Once the reader is available, point it to a UML model you want to read and you're of to the races:

var reader = XmiReaderBuilder.Create()
    .Build();

var xmiReaderResult = reader.Read("path-to-your-model");

var rootPackage = xmiReaderResult.QueryRoot("<xmi:id-of-the-root-package-you-are-interested-in>");

The IXmiReader can be configured with the IXmiReaderSettings interface, read more about reading an XMI document here

With Uml4Net it is also possible to process StereoTypes that have been applied to UML elements: their applications are resolved against their profile, their tagged values are typed, and they are written back. Read more about that here.

Writing a UML model

A model is written with an IXmiWriter, created with the XmiWriterBuilder. Writing the top-level elements of a document together with its XmiRoot writes the whole document back, including its documentation, MOF tags, stereotype applications and the content uml4net does not model:

var writer = XmiWriterBuilder.Create()
    .Build();

writer.Write(xmiReaderResult.DocumentRootElements, "path-to-the-written-model", xmiReaderResult.XmiRoot);

The IXmiWriter is configured with the IXmiWriterSettings interface, for example to include the packages that referenced elements belong to instead of writing href references, or to write Canonical XMI (XMI 2.5.1 Annex B). Read more about writing an XMI document here.

The deliberate design choices of uml4net, in the object model and in the XMI it writes, are recorded in design-decisions.md.

Code Quality

Quality Gate Status Code Smells Coverage Duplicated Lines (%) Lines of Code Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities

Installation

The package are available on Nuget at:

Build Status

GitHub actions are used to build and test the uml4net libraries

Branch Build Status
Master Build Status
Development Build Status

UML Documentation

The Object Management Group (OMG) is an international technology standards consortium. It was founded in 1989 with the goal of creating and maintaining vendor-neutral, interoperable, and portable standards for distributed computing. UML is one of the standards provided by OMG at http://www.omg.org/spec/UML/

License

The uml4net libraries are provided to the community under the Apache License 2.0.

Contributions

Contributions to the code-base are welcome. However, before we can accept your contributions we ask any contributor to sign the Contributor License Agreement (CLA) and send this digitaly signed to s.gerene@stariongroup.eu. You can find the CLA's in the CLA folder.

Contribution guidelines for this project

Clone this wiki locally