IntegerType
IIntegerType is a interface for features of integer types.
/// <summary>Integer type description</summary>
/// <remarks>Valid type has "MinValue" and "MaxValue" assigned.</remarks>
public interface IIntegerType : INumberType, IUnitProvider, IValueRangeProvider<BigInteger>
{
}
/// <summary>Description of number type features</summary>
public interface INumberType : IValueType
{
/// <summary>
/// Internal base type.
/// 2 for binaries, and 10 for decimal.
/// </summary>
int? Base { get; set; }
/// <summary>
/// Precision of significand digits in units of <see cref="Base"/>.
///
/// This is mantissa for floating point types, and integer digits for integer types.
/// For fixed points, the sum of <see cref="IRealType.IntegerPrecision"/> and <see cref="IRealType.FractionPrecision"/>.
///
/// Null if not valid for the number type.
/// </summary>
int? SignificandPrecision { get; set; }
/// <summary>Does the type have sign feature.</summary>
bool SignCapability { get; set; }
}
/// <summary>Provides Unit property.</summary>
public interface IUnitProvider
{
/// <summary>Unit property, e.g. "m/s".</summary>
string? Unit { get; set; }
}
/// <summary>Interface for min and max value range properties.</summary>
public interface IValueRangeProvider<T> where T : struct
{
/// <summary>Minimum value. Null if not valid for type, assigned or assignable.</summary>
Nullable<T> MinValue { get; set; }
/// <summary>Maximum value. Null if not valid for type, assigned or assignable.</summary>
Nullable<T> MaxValue { get; set; }
}
IntegerType is the default implementation.
IIntegerType datatype = new IntegerType
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Annotations = { },
Description = "",
Nullable = true,
Referable = true,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
SignCapability = false,
SignificandPrecision = 16,
Base = 2
}.SetReadOnly();
uint16 : IIntegerType { Base = 2, SignificandPrecision = 16, SignCapability = False, Nullable = True, Referable = True, Description = "", Annotations = [], MinValue = 0, MaxValue = 65536 }
IntegerTypeRequest is request for an integer type when sub-requests are needed.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
IntegerTypeRequest request = new IntegerTypeRequest
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Annotations = { },
Description = "",
Nullable = false,
Referable = null,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
SignCapability = false,
SignificandPrecision = 16,
Base = 2
};
// Query
IIntegerType datatype = service.GetRequired<IRequestFor<IIntegerType>, IIntegerType>(request);
DataTypeRequest<IIntegerType> is a request for integer type by Type.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
DataTypeRequest<IIntegerType> request = new(typeof(int));
// Request
IIntegerType datatype = service.GetRequired<DataTypeRequest<IIntegerType>, IIntegerType>(request);
int : IIntegerType { Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -2147483648, MaxValue = 2147483647 }
DataTypes facade contains type definitions for .NET types.
WriteLine(DataTypes.Bool.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.SByte.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Byte.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Short.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UShort.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Long.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.ULong.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.BigInteger.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
bool : IIntegerType { Base = 2, SignificandPrecision = 1, SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 1 } sbyte : IIntegerType { Base = 2, SignificandPrecision = 8, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -128, MaxValue = 127 } byte : IIntegerType { Base = 2, SignificandPrecision = 8, SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 255 } short : IIntegerType { Base = 2, SignificandPrecision = 16, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -32768, MaxValue = 32767 } ushort : IIntegerType { Base = 2, SignificandPrecision = 16, SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 65535 } int : IIntegerType { Base = 2, SignificandPrecision = 32, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -2147483648, MaxValue = 2147483647 } uint : IIntegerType { Base = 2, SignificandPrecision = 32, SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 4294967295 } long : IIntegerType { Base = 2, SignificandPrecision = 64, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -9223372036854775808, MaxValue = 9223372036854775807 } ulong : IIntegerType { Base = 2, SignificandPrecision = 64, SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 18446744073709551615 } BigInteger : IIntegerType { Base = 2, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0 }
Full Example
Full example
using System.Numerics;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class integertype
{
public static void Run()
{
{
// <01>
IIntegerType datatype = new IntegerType
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Annotations = { },
Description = "",
Nullable = true,
Referable = true,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
SignCapability = false,
SignificandPrecision = 16,
Base = 2
}.SetReadOnly();
// </01>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <03>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
IntegerTypeRequest request = new IntegerTypeRequest
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Annotations = { },
Description = "",
Nullable = false,
Referable = null,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
SignCapability = false,
SignificandPrecision = 16,
Base = 2
};
// Query
IIntegerType datatype = service.GetRequired<IRequestFor<IIntegerType>, IIntegerType>(request);
// </03>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <04>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
DataTypeRequest<IIntegerType> request = new(typeof(int));
// Request
IIntegerType datatype = service.GetRequired<DataTypeRequest<IIntegerType>, IIntegerType>(request);
// </04>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <05>
WriteLine(DataTypes.Bool.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.SByte.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Byte.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Short.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UShort.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Long.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.ULong.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.BigInteger.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
// </05>
}
}
}