LionWeb-CSharp 0.2.2-rc.1

This is a prerelease version of LionWeb-CSharp.
There is a newer version of this package available.
See the version list below for details.
dotnet add package LionWeb-CSharp --version 0.2.2-rc.1                
NuGet\Install-Package LionWeb-CSharp -Version 0.2.2-rc.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LionWeb-CSharp" Version="0.2.2-rc.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LionWeb-CSharp --version 0.2.2-rc.1                
#r "nuget: LionWeb-CSharp, 0.2.2-rc.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LionWeb-CSharp as a Cake Addin
#addin nuget:?package=LionWeb-CSharp&version=0.2.2-rc.1&prerelease

// Install LionWeb-CSharp as a Cake Tool
#tool nuget:?package=LionWeb-CSharp&version=0.2.2-rc.1&prerelease                

README

This project contains the C# implementation of (parts of) the LionWeb specification. Specifically supported are:

For convenience, the UML representation of the LionCore M3 meta-metamodel, including the separate LionCore built-ins language, is reproduced here:

A UML representation of the LionCore M3 meta-metamodel and LionCore built-ins

The LionCore built-ins language contains several classifiers (=instances of Classifier, so reside on the M2-level because they don't admit a self-definition) that can be used within any language definition. These specifically are

  • the INamed interface – because many concepts have a "name" property,
  • the generic Node concept – to use as the type of the target(s) of an untyped reference relation,
  • the four built-in primitive types.

Project organization

Various aspects of LionWeb are represented as directories at the top-level of this project.

C# generator for M2 types

The M2TypesGenerator class code generator generates C# code from a language defined using the LionCore M3 types. Each language generates to a separate file. Each generated file contains:

  • A class for each Concept instance, an interface for each Interface instance, and an enum for each Enumeration instance.
  • Each feature of a Classifier (i.e., a Concept or Interface – note that Annotation isn't supported yet) generates into a regular field with a getter, a setter, and no default value.
  • An implementation of INodeFactory to create any concrete (i.e.: non-abstract) Concept from this language, with a placeholder instance of Node for unknown Concepts.

Remarks:

  • The generated classes (eventually) extend Node. The generated interfacees (eventually) extend INode.
  • The generated fields are quite "dumb", and provide no convenience – at least, not at the moment. Care must be taken to "do the right thing". In particular, setting containment is done by setting the _Parent field of a node and adding the node to an appropriate field of that parent.

Generator details

The generators (for M2 types and "multi-factory") receive a TemplatesManager which discovers, loads, and compiles the templates in the generator/templates/ directory. A generator then invokes the GeneratorInstantiator<T>(string mainTemplateName) method to instantiate a CodeGenerator function which runs the indicated Handlebars main template with input data of the indicated type T. By invoking the WatchTemplates method of a TemplatesManager instance, a "watch mode" is triggered. Anytime a change occurs to the templates directory, a given action (typically: invoking a CodeGenerator function and saving the resulting string to file) is rerun. This is useful for working on the Handlebars templates without needing to restart entirely.

The C# code of a generator can be watched by executing a command of the following form:

$ dotnet watch run <main program>.cs

API

Languages

Serializing instances of Language as a LionWeb serialization chunk can be done as follows:

// serialization to internal format:
using LionWeb.Core.M2;
SerializationChunk serializationChunk = LanguageSerializer.Serialize(languages);

// serialization of internal format to JSON:
using LionWeb.Utils;
JsonUtils.WriteJsonToFile(<path>, serializationChunk);

(Also note that code in these snippets – in particular the using statements – might not be syntactically correct. Adjust before use.)

Deserializing a LionWeb serialization chunk containing one or more languages can be done as follows:

// read the JSON:
using LionWeb.Utils;
var serializationChunk = JsonUtils.ReadJsonFromFile<SerializationChunk>(<path>);

// perform the deserialization:
using LionWeb.Core.M3;
IEnumerable<Language> languages = LanguageDeserializer.Deserialize(serializationChunk);

Instances

Serializing nodes (as instances of Node) can be done as follows:

// serialization to internal format:
using LionWeb.Core.Serialization;
var serializationChunk = Serializer.Serialize(<nodes>);

// serialization of internal format to JSON:
using LionWeb.Utils;
JsonUtils.WriteJsonToFile(<path>, serializationChunk);

Deserializing a LionWeb serialization chunk that's the serialization of nodes from one language can be done as follows:

// read the JSON:
using LionWeb.Utils;
var serializationChunk = JsonUtils.ReadJsonFromFile<SerializationChunk>(<path>);

// perform the deserialization:
using LionWeb.Core;
using LionWeb.Core.M3;
var (Language language, INodeFactory factory) languageWithFactory = (<language instance>, <its corresponding INodeFactory implementation>);
var deserializer = new Deserializer(languageWithFactory);
using LionWeb.Core.Serialization;
List<Node> nodes = deserializer.Deserialize(serializationChunk);

The argument to the constructor of the Deserializer is a parameter array, so add a tuple with a Language instance and a corresponding implementation of INodeFactory for all languages that the serialization chunk uses – see its languages field.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on LionWeb-CSharp:

Package Downloads
LionWeb-CSharp-Generator

A generator that generates C# source code from a LionWeb M2

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.4-beta.0 0 1/15/2025
0.2.3 67 1/13/2025
0.2.3-rc.2 27 1/13/2025
0.2.3-rc.1.1 0 1/15/2025
0.2.3-rc.1 82 12/4/2024
0.2.2 137 10/21/2024
0.2.2-rc.7 77 9/17/2024
0.2.2-rc.6 112 7/16/2024
0.2.2-rc.5 54 7/11/2024
0.2.2-rc.4 58 7/9/2024
0.2.2-rc.3 44 7/9/2024
0.2.2-rc.2 55 7/5/2024
0.2.2-rc.1 74 7/5/2024