ListIndexOf
List writer that searches index of element implements IWriterToRef<(List, Element), Long>.
IWriterToRef<(List<int>, int), long> listIndexOf;
Creating a writer
ListIndexOf<List, Element> is the default implementation IList<T>.
IWriterToRef<(List<int>, int), long> listIndexOf = new ListIndexOf<List<int>, int>();
ListIndexOf.Create(listType, elementType) also creates the writer.
IWriterToRef<(List<int>, int), long> listIndexOf =
(IWriterToRef<(List<int>, int), long>)
ListIndexOf.Create(typeof(List<int>), typeof(int));
List index of be adapted from delegate.
IWriterToRef<(List<int>, int), long> listIndexOf =
DelegateWriter.Reader<(List<int>, int), long>(
((List<int> list, int element) args) => args.list.IndexOf(args.element)
);
ListIndexOfRequest(Type) is a request to build a list indexof writer.
ListIndexOfRequest listRequest = new ListIndexOfRequest(typeof(List<int>));
IWriterToRef<(List<int>, int), long> listIndexOf =
AccessorServices.Instance
.GetRequired<ListIndexOfRequest, IWriterToRef<(List<int>, int), long>>(listRequest);
Usage
Writer finds index of an element.
List<int> list = new List<int> { 1, 2, 3 };
long index = listIndexOf.Read((list, 2));
Full Example
Full example
using System.Collections.Generic;
using Avalanche.Accessor;
using Avalanche.Accessor.List;
using Avalanche.Writer;
public class listindexof
{
public static void Run()
{
{
#pragma warning disable CS0168
// <01>
IWriterToRef<(List<int>, int), long> listIndexOf;
// </01>
#pragma warning restore CS0168
}
{
// <10>
IWriterToRef<(List<int>, int), long> listIndexOf = new ListIndexOf<List<int>, int>();
// </10>
List<int> list = new List<int> { 1, 2, 3 };
long index = listIndexOf.Read((list, 2));
}
{
// <11>
IWriterToRef<(List<int>, int), long> listIndexOf =
(IWriterToRef<(List<int>, int), long>)
ListIndexOf.Create(typeof(List<int>), typeof(int));
// </11>
List<int> list = new List<int> { 1, 2, 3 };
long index = listIndexOf.Read((list, 2));
}
{
// <12>
IWriterToRef<(List<int>, int), long> listIndexOf =
DelegateWriter.Reader<(List<int>, int), long>(
((List<int> list, int element) args) => args.list.IndexOf(args.element)
);
// </12>
List<int> list = new List<int> { 1, 2, 3 };
long index = listIndexOf.Read((list, 2));
}
{
// <16>
ListIndexOfRequest listRequest = new ListIndexOfRequest(typeof(List<int>));
IWriterToRef<(List<int>, int), long> listIndexOf =
AccessorServices.Instance
.GetRequired<ListIndexOfRequest, IWriterToRef<(List<int>, int), long>>(listRequest);
// </16>
List<int> list = new List<int> { 1, 2, 3 };
long index = listIndexOf.Read((list, 2));
}
{
IWriterToRef<(List<int>, int), long> listIndexOf = new ListIndexOf<List<int>, int>();
// <21>
List<int> list = new List<int> { 1, 2, 3 };
long index = listIndexOf.Read((list, 2));
// </21>
}
}
}