ListGet
List getter writer is IWriterToRef<(List, long), Element> writer implementation, where 'long' is the element index.
IWriterToRef<(List<int>, long), int> listGet;
Creating a writer
ListGet<List, Element> is default list writer for IList<T>.
IWriterToRef<(List<int>, long), int> listGet = new ListGet<List<int>, int>();
List.Create(listType, elementType) also creates the writer.
IWriterToRef<(List<int>, long), int> listGet =
(IWriterToRef<(List<int>, long), int>)
ListGet.Create(typeof(List<int>), typeof(int));
List get be adapted from delegate.
IWriterToRef<(List<int>, long), int> listGet =
DelegateWriter.Reader<(List<int>, long), int>(args => args.Item1[(int)args.Item2]);
ListGetRequest(Type) is a request to build a list get writer.
ListGetRequest listRequest = new ListGetRequest(typeof(List<int>));
IWriterToRef<(List<int>, long), int> listGet =
AccessorServices.Instance
.GetRequired<ListGetRequest, IWriterToRef<(List<int>, long), int>>(listRequest);
Usage
Writer gets an element at index.
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
Full Example
Full example
using System.Collections.Generic;
using Avalanche.Accessor;
using Avalanche.Accessor.List;
using Avalanche.Writer;
public class listget
{
public static void Run()
{
{
#pragma warning disable CS0168
// <01>
IWriterToRef<(List<int>, long), int> listGet;
// </01>
#pragma warning restore CS0168
}
{
// <10>
IWriterToRef<(List<int>, long), int> listGet = new ListGet<List<int>, int>();
// </10>
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
}
{
// <11>
IWriterToRef<(List<int>, long), int> listGet =
(IWriterToRef<(List<int>, long), int>)
ListGet.Create(typeof(List<int>), typeof(int));
// </11>
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
}
{
// <12>
IWriterToRef<(List<int>, long), int> listGet =
DelegateWriter.Reader<(List<int>, long), int>(args => args.Item1[(int)args.Item2]);
// </12>
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
}
{
// <16>
ListGetRequest listRequest = new ListGetRequest(typeof(List<int>));
IWriterToRef<(List<int>, long), int> listGet =
AccessorServices.Instance
.GetRequired<ListGetRequest, IWriterToRef<(List<int>, long), int>>(listRequest);
// </16>
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
}
{
IWriterToRef<(List<int>, long), int> listGet = new ListGet<List<int>, int>();
// <21>
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
// </21>
}
}
}