IMapType
IMapType is interface for map descriptions.
/// <summary>Map type description.</summary>
/// <remarks>Valid map has <see cref="Key"/> and <see cref="Value"/> assigned.</remarks>
public interface IMapType : IDataType, ICyclical
{
/// <summary>Key type</summary>
IDataTypeBase Key { get; set; }
/// <summary>Value type</summary>
IDataTypeBase Value { get; set; }
}
MapType is the default implementation.
IMapType mapType = new MapType
{
Name = Identities.CreateNamespace("Namespace").AppendName("MyMap").SetReadOnly(),
Annotations = null!,
Description = "",
Nullable = true,
Referable = true,
Key = DataTypes.String,
Value = DataTypes.Int
}.SetReadOnly();
Namespace.MyMap : IMapType ├── Key = string : IStringType │ └── Element = char : IIntegerType └── Value = int : IIntegerType
MapTypeRequest is request for a map type when sub-requests are needed.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create map request
MapTypeRequest mapRequest = new MapTypeRequest
{
Name = Identities.CreateName("MyMap"),
Annotations = null,
Description = null,
Nullable = null,
Referable = null,
Key = new DataTypeRequest<IDataTypeBase>(typeof(string)),
Value = new DataTypeRequest<IDataTypeBase>(typeof(int))
};
// Request map
IMapType mapType = service.GetRequired<MapTypeRequest, IMapType>(mapRequest);
MyMap : IMapType ├── Key = string : IStringType │ └── Element = char : IIntegerType └── Value = int : IIntegerType
DataTypeRequest<IMapType> is a request for map type of Type.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create map request
DataTypeRequest<IMapType> mapRequest = new(typeof(Dictionary<string, int>));
// Request map
IMapType mapType = service.GetRequired<IDataTypeRequest, IMapType>(mapRequest);
System.Collections.Generic.Dictionary`2[[System.String],[System.Int32]] : IMapType ├── Key = string : IStringType │ └── Element = char : IIntegerType └── Value = int : IIntegerType
Default handlers process IDictionary<K,V> types on DataTypeRequest<T>.
DataTypeRequest<IMapType> mapRequest = new(typeof(IDictionary<string, int>));
DataTypeRequest<IMapType> mapRequest = new(typeof(ConcurrentDictionary<string, int>));
Full Example
Full example
using System.Collections.Concurrent;
using System.Collections.Generic;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class maptype
{
public static void Run()
{
{
// <01>
IMapType mapType = new MapType
{
Name = Identities.CreateNamespace("Namespace").AppendName("MyMap").SetReadOnly(),
Annotations = null!,
Description = "",
Nullable = true,
Referable = true,
Key = DataTypes.String,
Value = DataTypes.Int
}.SetReadOnly();
// </01>
// Print
WriteLine(mapType.PrintTree());
}
{
// <03>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create map request
MapTypeRequest mapRequest = new MapTypeRequest
{
Name = Identities.CreateName("MyMap"),
Annotations = null,
Description = null,
Nullable = null,
Referable = null,
Key = new DataTypeRequest<IDataTypeBase>(typeof(string)),
Value = new DataTypeRequest<IDataTypeBase>(typeof(int))
};
// Request map
IMapType mapType = service.GetRequired<MapTypeRequest, IMapType>(mapRequest);
// </03>
// Print
WriteLine(mapType.PrintTree());
}
{
// <04>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create map request
DataTypeRequest<IMapType> mapRequest = new(typeof(Dictionary<string, int>));
// Request map
IMapType mapType = service.GetRequired<IDataTypeRequest, IMapType>(mapRequest);
// </04>
// Print
WriteLine(mapType.PrintTree());
}
{
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create map request
// <05>
DataTypeRequest<IMapType> mapRequest = new(typeof(IDictionary<string, int>));
// </05>
// Request map
IMapType mapType = service.GetRequired<IDataTypeRequest, IMapType>(mapRequest);
// Print
WriteLine(mapType.PrintTree());
}
{
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance));
// Create map request
// <06>
DataTypeRequest<IMapType> mapRequest = new(typeof(ConcurrentDictionary<string, int>));
// </06>
// Request map
IMapType mapType = service.GetRequired<IDataTypeRequest, IMapType>(mapRequest);
// Print
WriteLine(mapType.PrintTree());
}
}
}