ListReferer
Referer that refers to an element of a list implements interface IRefererBase<(Element, long), List>.
ListReferer.Create(type) creates implementation for lists that implement IList<T>.
// Create referer
IReferer<(List<int>, long), int> referer = (IReferer<(List<int>, long), int>)ListReferer.Create(typeof(List<int>));
Referer gets a reference to an element.
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Get pointer to index '2'
ref int elementPointer = ref referer.GetReference((list, 2));
// Read
WriteLine(elementPointer);
// Write
elementPointer = 100;
// Read
WriteLine(list[2]);
ListReferer.Create(type) creates implementation for arrays as well.
// Create referer
IReferer<(int[], long), int> referer = (IReferer<(int[], long), int>)ListReferer.Create(typeof(int[]));
Array elements are referable as well.
// Create list
int[] array = new int[] { 4, 5, 6 };
// Get pointer to index '2'
ref int elementPointer = ref referer.GetReference((array, 2));
// Read
WriteLine(elementPointer);
// Write
elementPointer = 100;
// Read
WriteLine(array[2]);
ListRefererRequest is request to query a list-element-referer from service.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, AccessorHandlers.Instance), CachePolicies.Default);
// Create request
IRequest request = new ListRefererRequest(typeof(List<int>));
// Create referer
IReferer<(List<int>, long), int> referer = service.GetRequired<IRequest, IReferer<(List<int>, long), int>>(request);
Full Example
Full example
using System.Collections.Generic;
using Avalanche.Accessor;
using Avalanche.Accessor.List;
using Avalanche.Service;
using Avalanche.Writer;
using static System.Console;
class listreferer
{
public static void Run()
{
{
// <01>
// Create referer
IReferer<(List<int>, long), int> referer = (IReferer<(List<int>, long), int>)ListReferer.Create(typeof(List<int>));
// </01>
// <02>
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Get pointer to index '2'
ref int elementPointer = ref referer.GetReference((list, 2));
// Read
WriteLine(elementPointer);
// Write
elementPointer = 100;
// Read
WriteLine(list[2]);
// </02>
}
{
// <11>
// Create referer
IReferer<(int[], long), int> referer = (IReferer<(int[], long), int>)ListReferer.Create(typeof(int[]));
// </11>
// <12>
// Create list
int[] array = new int[] { 4, 5, 6 };
// Get pointer to index '2'
ref int elementPointer = ref referer.GetReference((array, 2));
// Read
WriteLine(elementPointer);
// Write
elementPointer = 100;
// Read
WriteLine(array[2]);
// </12>
}
{
// <21>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, AccessorHandlers.Instance), CachePolicies.Default);
// Create request
IRequest request = new ListRefererRequest(typeof(List<int>));
// Create referer
IReferer<(List<int>, long), int> referer = service.GetRequired<IRequest, IReferer<(List<int>, long), int>>(request);
// </21>
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Get pointer to index '2'
ref int elementPointer = ref referer.GetReference((list, 2));
// Read
WriteLine(elementPointer);
// Write
elementPointer = 100;
// Read
WriteLine(list[2]);
}
}
}