EnumerationType
IEnumerationType is a description of enumeration types.
/// <summary>Enumeration type description</summary>
public interface IEnumerationType : IIntegerType
{
/// <summary>Enumeration values.</summary>
IValue[] Values { get; set; }
/// <summary>Description of enumeration value.</summary>
public interface IValue
{
/// <summary>Numeric value</summary>
BigInteger Value { get; set; }
/// <summary>Name of the enumeration.</summary>
object Name { get; set; }
}
/// <summary>Keys for wellknown keys for <see cref="IDataType.Properties"/>.</summary>
public new static class Property
{
/// <summary>Indicates that enumeration values are flags</summary>
public const string Flags = "System.FlagsAttribute";
}
}
IDataType └── IValueType └── INumberType └── IIntegerType └── IEnumerationType
EnumerationType is the default implementation.
IEnumerationType datatype = new EnumerationType
{
Name = Identities.CreateName("MyEnum").SetReadOnly(),
Properties = { },
Description = null!,
Unassignable = true,
Referable = true,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Values = new IEnumerationType.IValue[]
{
new EnumerationValue(0, Identities.CreateName("Car")),
new EnumerationValue(1, Identities.CreateName("Truck")),
new EnumerationValue(2, Identities.CreateName("Bike")),
new EnumerationValue(3, Identities.CreateName("Plain")),
new EnumerationValue(4, Identities.CreateName("Train"))
}
}.SetReadOnly();
IEnumerationType { Name = "MyEnum" , Values = [IValue(0, Name("Car")), IValue(1, Name("Truck")), IValue(2, Name("Bike")), IValue(3, Name("Plain")), IValue(4, Name("Train"))], Signed = False, Nullable = True, Referable = True, Annotations = [], MinValue = 0, MaxValue = 65536 }
EnumerationTypeRequest is request for an enumeration type when sub-requests are needed.
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
EnumerationTypeRequest request = new EnumerationTypeRequest
{
Name = Identities.CreateName("MyEnum").SetReadOnly(),
Properties = new Dictionary<string, string> { },
Unassignable = null,
Referable = null,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Values = new IEnumerationType.IValue[]
{
new EnumerationValue(0, Identities.CreateName("Car")),
new EnumerationValue(1, Identities.CreateName("Truck")),
new EnumerationValue(2, Identities.CreateName("Bike")),
new EnumerationValue(3, Identities.CreateName("Plain")),
new EnumerationValue(4, Identities.CreateName("Train"))
}
};
// Query
IEnumerationType datatype = service.GetRequired<IRequestFor<IEnumerationType>, IEnumerationType>(request);
DataTypeRequest(DtoTarget.Integer) is a request for enumeration type by Type. (Avalanche.DataType.Dto.dll)
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
DataTypeRequest request = new(DtoTarget.Integer(typeof(MyEnum)));
// Request
IEnumerationType datatype = service.GetRequired<DataTypeRequest, IEnumerationType>(request);
IEnumerationType { Name = "enumerationtype+MyEnum" , Values = [IValue(0, Name("Car")), IValue(1, Name("Truck")), IValue(2, Name("Bike")), IValue(3, Name("Plane")), IValue(4, Name("Train"))], Signed = False, Nullable = False, Referable = False, Annotations = [], MinValue = 0, MaxValue = 65535 }
Full Example
Full example
using System.Collections.Generic;
using System.Numerics;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class enumerationtype
{
public static void Run()
{
{
// <01>
IEnumerationType datatype = new EnumerationType
{
Name = Identities.CreateName("MyEnum").SetReadOnly(),
Properties = { },
Description = null!,
Unassignable = true,
Referable = true,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Values = new IEnumerationType.IValue[]
{
new EnumerationValue(0, Identities.CreateName("Car")),
new EnumerationValue(1, Identities.CreateName("Truck")),
new EnumerationValue(2, Identities.CreateName("Bike")),
new EnumerationValue(3, Identities.CreateName("Plain")),
new EnumerationValue(4, Identities.CreateName("Train"))
}
}.SetReadOnly();
// </01>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <03>
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
EnumerationTypeRequest request = new EnumerationTypeRequest
{
Name = Identities.CreateName("MyEnum").SetReadOnly(),
Properties = new Dictionary<string, string> { },
Unassignable = null,
Referable = null,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Values = new IEnumerationType.IValue[]
{
new EnumerationValue(0, Identities.CreateName("Car")),
new EnumerationValue(1, Identities.CreateName("Truck")),
new EnumerationValue(2, Identities.CreateName("Bike")),
new EnumerationValue(3, Identities.CreateName("Plain")),
new EnumerationValue(4, Identities.CreateName("Train"))
}
};
// Query
IEnumerationType datatype = service.GetRequired<IRequestFor<IEnumerationType>, IEnumerationType>(request);
// </03>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <04>
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
DataTypeRequest request = new(DtoTarget.Integer(typeof(MyEnum)));
// Request
IEnumerationType datatype = service.GetRequired<DataTypeRequest, IEnumerationType>(request);
// </04>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
}
// <99>
public enum MyEnum : ushort { Car, Truck, Bike, Plane, Train }
// </99>
}