IFieldType
IFieldType is an interface for basic properties record fields types of various schemas.
/// <summary>Field type description.</summary>
public interface IFieldType : IDataType, ICyclical
{
/// <summary>Field's value type.</summary>
//[RequiredMember]
IDataType Value { get; set; }
/// <summary>Keys for wellknown keys for <see cref="IDataType.Annotations"/>.</summary>
public new static class Annotation
{
/// <summary>Indicates that this field represents a key of the record type. If there are multiple fields as a key, their composition is the complete key.</summary>
public const string Key = nameof(Key);
/// <summary>Field arrangement order</summary>
public const string Order = nameof(Order);
}
}
IDataType └── IFieldType
FieldType is the default implementation.
IFieldType datatype = new FieldType
{
Name = Identities.CreateName("Name").SetReadOnly(),
Annotations = { },
Description = "This fields contains name of the record",
Unassignable = true,
Referable = false,
Value = DataTypes.String.Instance
}.SetReadOnly();
IFieldType { Name = "Name" , Nullable = True, Referable = False, Description = "This fields contains name of the record", Annotations = [] } └── Value = IStringType { Name = "string" , Encoding = "Unicode", Nullable = True, Referable = True, Description = "Unicode UTF-16", Annotations = [], MinLength = 0, MaxLength = 2147483647 } └── Element = IIntegerType { Name = "char" , SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = , MinValue = 0, MaxValue = 65535 }
FieldTypeRequest is request for a field type when sub-requests are needed.
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
FieldTypeRequest request = new FieldTypeRequest
{
Name = Identities.CreateName("Name").SetReadOnly(),
Annotations = new Dictionary<string, string> { { IDataType.Annotation.Description, "This fields contains name of the record" } },
Unassignable = true,
Referable = false,
Value = new DataTypeRequest<NetType>(typeof(string))
};
// Query
IFieldType datatype = service.GetRequired<IRequestFor<IFieldType>, IFieldType>(request);
Annotations
Well-known annotations.
Field | Key | Type | Description |
---|---|---|---|
IFieldType.Annotation.Key | Key | bool | Indicates that this field represents the a key of the record type. If there are multiple fields as a key, their composition is the complete key. |
IFieldType.Annotation.Order | Order | long | Field arrangement order. Also used as Protobuf serialization order. Starts at 1 and upwards. 0 is unassigned. |
Full Example
Full example
using System.Collections.Generic;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class fieldtype
{
public static void Run()
{
{
// <01>
IFieldType datatype = new FieldType
{
Name = Identities.CreateName("Name").SetReadOnly(),
Annotations = { },
Description = "This fields contains name of the record",
Unassignable = true,
Referable = false,
Value = DataTypes.String.Instance
}.SetReadOnly();
// </01>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <03>
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
FieldTypeRequest request = new FieldTypeRequest
{
Name = Identities.CreateName("Name").SetReadOnly(),
Annotations = new Dictionary<string, string> { { IDataType.Annotation.Description, "This fields contains name of the record" } },
Unassignable = true,
Referable = false,
Value = new DataTypeRequest<NetType>(typeof(string))
};
// Query
IFieldType datatype = service.GetRequired<IRequestFor<IFieldType>, IFieldType>(request);
// </03>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
}
}