Table of Contents

Class Entity

Namespace
ROCrates.Models
Assembly
ROCrates.Net.dll

This class represents the base Entity used in an ROCrate.

public class Entity
Inheritance
Entity
Derived
Inherited Members

Constructors

Entity()

public Entity()

Entity(ROCrate?, string?, JsonObject?)

public Entity(ROCrate? crate = null, string? identifier = null, JsonObject? properties = null)

Parameters

crate ROCrate
identifier string
properties JsonObject

Properties

Id

public string Id { get; set; }

Property Value

string

Properties

public JsonObject Properties { get; set; }

Property Value

JsonObject

RoCrate

public ROCrate? RoCrate { get; set; }

Property Value

ROCrate

Methods

AppendTo<T>(string, T)

Append a value to the entity's property.

public void AppendTo<T>(string key, T value) where T : Entity

Parameters

key string

The element to append the value to.

value T

The value to be appended.

Type Parameters

T

The type of Entity to be appended.

Examples

var roCrate = new ROCrate();
var rootDataset = new RootDataset(roCrate);
var person = new Person(roCrate, identifier: "Alice");
rootDataset.AppendTo("author", person);

Exceptions

Exception

Thrown when attempting to append to reserved key (those starting with '@').

NullReferenceException

Thrown when value is null.

DeleteProperty(string)

Remove a property from the Properties field.

public void DeleteProperty(string propertyName)

Parameters

propertyName string

Deserialize(string, ROCrate)

Create an Entity from JSON properties.

public static Entity? Deserialize(string entityJson, ROCrate roCrate)

Parameters

entityJson string

The JSON representing the Entity

roCrate ROCrate

The RO-Crate for the Entity

Returns

Entity

The deserialised Entity

GetCanonicalId()

Get the canonical ID of the crate that the entity is in.

[Obsolete("GetCanonicalId is deprecated. Use Id property instead.")]
public string GetCanonicalId()

Returns

string

GetProperty<T>(string)

Retrieve a property from Properties deserialsed as type T.

public T? GetProperty<T>(string propertyName)

Parameters

propertyName string

The name of the property to retrieve.

Returns

T

The property as type T if the property exists, or null if the property does no exist on the entity.

T

Type Parameters

T

The type to deserialise the property into.

Serialize()

Convert Entity to JSON string.

public virtual string Serialize()

Returns

string

The Entity as a JSON string.

SetProperty<T>(string, T)

Sersialise a property into the Properties field. This will update a property if it already exists.

public void SetProperty<T>(string propertyName, T property)

Parameters

propertyName string
property T

Type Parameters

T