Class Entity
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
ROCrateidentifier
stringproperties
JsonObject
Properties
Id
public string Id { get; set; }
Property Value
Properties
public JsonObject Properties { get; set; }
Property Value
RoCrate
public ROCrate? RoCrate { get; set; }
Property Value
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
stringThe element to append the value to.
value
TThe 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
isnull
.
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
Returns
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
GetProperty<T>(string)
Retrieve a property from Properties
deserialsed as type T
.
public T? GetProperty<T>(string propertyName)
Parameters
propertyName
stringThe name of the property to retrieve.
Returns
- T
The property as type
TT
if the property exists, ornull
if the property does no exist on the entity.
Type Parameters
T
The type to deserialise the property into.
Serialize()
Convert Entity to JSON string.
public virtual string Serialize()
Returns
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
stringproperty
T
Type Parameters
T