Skip to main content

LionWeb Introduction for C# Developers

note

In this document, the term property and reference may refer to both C# and LionWeb contexts. We'll qualify them with "C#" or "LionWeb" for clarity.

Everything is an Object / Node

In object-oriented languages like C#, everything is an object. Objects have an identity, state, and a type — the object's class. The object's identity is its memory location, and its state is the value of all its members. Relevant members are fields and C# properties.

In LionWeb, everything is a node. Nodes have an id, state, and a classifier — the node's concept. The id is a string consisting of uppercase/lowercase A-Z, 1-9, -, and _. Like object identity in C#, a node id must be unique but has no semantic meaning.

A node’s state is the value of all its features: these can be LionWeb properties[^prefix], containments, or LionWeb references.

C#LionWeb
objectnode
object identitynode id
object typenode classifier
classconcept
class memberconcept feature
field + C# propertyLionWeb property + containment + LionWeb reference

... except Value Types / LionWeb Properties

C# has value types that are not objects. Examples include int and bool. They don't have any identity; they are purely defined by their value.

We cannot tell apart 15 from 15, but we can tell apart the two objects:

var a = new Person { Firstname = "John", Lastname = "Doe" };
var b = new Person { Firstname = "John", Lastname = "Doe" };

Value types cannot be null, unless we declare them nullable:

int age = 23;
int? numberOfAunts = null;

In this example, we always know the person's age, but we might not know how many aunts they have.

LionWeb properties have value type semantics1, meaning they are purely defined by their value. They can have type integer, boolean, enumeration, or string.

LionWeb properties are either required or optional. If required, the LionWeb property must have a value; otherwise, the value can be omitted.

Mapping to C#

LionWeb properties become C# properties with proper getters and setters. In C# we also have a method like Person SetFirstname(string value). They form a fluent interface.

Optional LionWeb properties have nullable types in C#. They may return null, and can be set to null.

Required LionWeb properties have non-nullable types in C#. They may never return null. If no value has ever been assigned to this C# property, the C# property getter throws an UnsetFeatureException. If set to null, the C# property setter, and the SetProperty() method, throw an InvalidValueException.

class Person {
...
public string Firstname { get; set; }
public Person SetFirstname(string value);

public string? Lastname { get; set; }
public Person SetLastname(string? value);
}

...

Person johnDoe = new Person("g1_X");

johnDoe.Firstname; // throws UnsetFeatureException

johnDoe
.SetFirstname("John")
.SetLastname("Doe");

johnDoe.Firstname = null; // throws InvalidValueException
johnDoe.SetFirstname(null); // throws InvalidValueException
C#LionWeb
int typeinteger property type
bool typeboolean property type
string typestring property type
enumenumeration
nullable typeoptional feature
non-nullable typerequired feature

Footnotes

  1. Value type semantics because C# string is not a value type.