RecordType from class
DataTypeRequest<NetRecord> is record type request for record-like class and struct types. (Avalanche.DataType.Net.dll)
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
DataTypeRequest<NetRecord> request = new(typeof(Node));
// Query
IRecordType datatype = service.GetRequired<DataTypeRequest<NetRecord>, IRecordType>(request);
Note that referable classes should be sealed so that DataTypeRequest<NetType> identifies as IRecordType and not as IAnyType.
[Description("Graph node")]
public sealed class Node
{
[Description("Identity")]
public readonly int Id;
[Description("Forward edges")]
public List<Node> Edges = new List<Node>();
public Node(int id) => Id = id;
}
recordtype+Node, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IRecordType ├── Fields[0] = Id : IFieldType │ └── Value = int : IIntegerType └── Fields[1] = Edges : IFieldType └── Value = System.Collections.Generic.List`1[[recordtype+Node]] : IListType └── Element = recordtype+Node, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IRecordType
Note the annotations that can be placed on fields.
Full Example
Full example
using System.Collections.Generic;
using System.ComponentModel;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class @class
{
public static void Run()
{
{
// <04>
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
DataTypeRequest<NetRecord> request = new(typeof(Node));
// Query
IRecordType datatype = service.GetRequired<DataTypeRequest<NetRecord>, IRecordType>(request);
// </04>
// Print
WriteLine(datatype.PrintTree());
}
}
// <99>
[Description("Graph node")]
public sealed class Node
{
[Description("Identity")]
public readonly int Id;
[Description("Forward edges")]
public List<Node> Edges = new List<Node>();
public Node(int id) => Id = id;
}
// </99>
}