StringType
IStringType is a description of string types.
/// <summary>String type description</summary>
/// <remarks>Valid type doesn't need any of the fields.</remarks>
public interface IStringType : IListType
{
/// <summary>Regex pattern for valid values.</summary>
string? Pattern { get; set; }
/// <summary>Character encoding of this string type. e.g. "ASCII" "UTF-8" "UTF-16" "UTF-32"</summary>
string? Encoding { get; set; }
}
StringType is the default implementation.
IStringType datatype = new StringType
{
Name = Identities.CreateName("string").SetReadOnly(),
Annotations = { },
Description = "",
Nullable = true,
Referable = true,
Element = DataTypes.Char
}.SetReadOnly();
IStringType { Name = "string" , Nullable = True, Referable = True, Description = "", Annotations = [], MinLength = 0, MaxLength = 2147483647 } └── Element = IIntegerType { Name = "char" , SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = , MinValue = 0, MaxValue = 65535 }
StringTypeRequest is request for a string type when sub-requests are needed.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
StringTypeRequest request = new StringTypeRequest
{
Name = Identities.CreateName("string").SetReadOnly(),
Annotations = { },
Description = null,
Nullable = null,
Referable = null,
Element = new DataTypeRequest<IDataTypeBase>(typeof(char))
};
// Query
IStringType datatype = service.GetRequired<IRequestFor<IStringType>, IStringType>(request);
IStringType { Name = "string" , Nullable = False, Referable = False, Annotations = [], MinLength = 0, MaxLength = 2147483647 } └── Element = IIntegerType { Name = "char" , SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = , MinValue = 0, MaxValue = 65535 }
DataTypeRequest<IStringType> is a request for string type by Type.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
DataTypeRequest<IStringType> request = new(typeof(string));
// Request record
IStringType datatype = service.GetRequired<DataTypeRequest<IStringType>, IStringType>(request);
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 }
DataTypes facade contains type definition for .NET type.
IStringType datatype0 = DataTypes.String;
Full Example
Full example
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class stringtype
{
public static void Run()
{
{
// <01>
IStringType datatype = new StringType
{
Name = Identities.CreateName("string").SetReadOnly(),
Annotations = { },
Description = "",
Nullable = true,
Referable = true,
Element = DataTypes.Char
}.SetReadOnly();
// </01>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <03>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
StringTypeRequest request = new StringTypeRequest
{
Name = Identities.CreateName("string").SetReadOnly(),
Annotations = { },
Description = null,
Nullable = null,
Referable = null,
Element = new DataTypeRequest<IDataTypeBase>(typeof(char))
};
// Query
IStringType datatype = service.GetRequired<IRequestFor<IStringType>, IStringType>(request);
// </03>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <04>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create request
DataTypeRequest<IStringType> request = new(typeof(string));
// Request record
IStringType datatype = service.GetRequired<DataTypeRequest<IStringType>, IStringType>(request);
// </04>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <05>
IStringType datatype0 = DataTypes.String;
// </05>
}
}
}