LionWeb-CSharp
0.2.2-rc.7
See the version list below for details.
dotnet add package LionWeb-CSharp --version 0.2.2-rc.7
NuGet\Install-Package LionWeb-CSharp -Version 0.2.2-rc.7
<PackageReference Include="LionWeb-CSharp" Version="0.2.2-rc.7" />
paket add LionWeb-CSharp --version 0.2.2-rc.7
#r "nuget: LionWeb-CSharp, 0.2.2-rc.7"
// Install LionWeb-CSharp as a Cake Addin #addin nuget:?package=LionWeb-CSharp&version=0.2.2-rc.7&prerelease // Install LionWeb-CSharp as a Cake Tool #tool nuget:?package=LionWeb-CSharp&version=0.2.2-rc.7&prerelease
README
This project contains the C# implementation of (parts of) the LionWeb specification. Specifically supported are:
- language definition through the LionCore M3 meta-metamodel,
- serialization and deserialization of both languages and instances of those conforming to the LionWeb JSON serialization format,
- a generic, dynamic/reflective base implementation of nodes,
- C# type generation.
For convenience, the UML representation of the LionCore M3 meta-metamodel, including the separate LionCore built-ins language, is reproduced here:
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.
core/
:- base types,
Node
, a generic, dynamic/reflective implementation ofINode
, release version declaration M2/
: LionCore built-insM3/
: implementation of the LionCore M3 to define languages with, computed properties and extension methods defined on top of those, and (de-)serialization of language definitionsserialization/
: implementation of (de-)serialization for theNode
type, and definition of the serialization chunk format (after it's been unmarshalled from JSON)
- base types,
docs/
: documentation, mainly in the form of diagramsutils/
: utilities, mainly intended for internal use but occasionally – such asJsonUtils
– useful outside of that as wellgenerator/
: a C# generator for M2 types - see theM2TypesGenerator
class andMultiLanguageNodeFactoryGenerator
classes
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 eachConcept
instance, aninterface
for eachInterface
instance, and anenum
for eachEnumeration
instance. - Each feature of a
Classifier
(i.e., aConcept
orInterface
– note thatAnnotation
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 ofNode
for unknownConcept
s.
Remarks:
- The generated
class
es (eventually) extendNode
. The generatedinterface
es (eventually) extendINode
. - 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 | Versions 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. |
-
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 |