IList<T>
AccessorRequest<NetList> requests a list accessor for .NET types that implement IList<>. (Avalanche.Accessor.Net.dll)
// Create service
IService service = Services.Create(NetAccessorHandlers.Instance);
// Create container target
IContainerTarget target = new NetList(typeof(List<int>));
// Create request
IRequestFor<IAccessor> request = new AccessorRequest(target);
// Issue request
IListAccessor<List<int>, int> accessor = service.GetRequired<IRequest, IListAccessor<List<int>, int>>(request);
Query
AccessorRequest(target) requests a IAccessor depending on type target.
// Create service
IService service = Services.Create(NetAccessorHandlers.Instance);
// Create container target
IContainerTarget target = new NetList(typeof(List<int>));
// Create request
IRequestFor<IAccessor> request = new AccessorRequest(target);
// Issue request
IListAccessor<List<int>, int> accessor = service.GetRequired<IRequest, IListAccessor<List<int>, int>>(request);
ListAccessorRequest(target) requests a IListAccessor<List, Element> for .NET types that implement IList<>.
// Create service
IService service = Services.Create(NetAccessorHandlers.Instance);
// Create container target
IContainerTarget target = new NetList(typeof(List<int>));
// Create request
IRequestFor<IListAccessor> request = new ListAccessorRequest(target);
// Issue request
IListAccessor<List<int>, int> accessor = service.GetRequired<IRequest, IListAccessor<List<int>, int>>(request);
ListAccessorRequest is specifically a request for specific writers. Each can be assigned with explicit customization.
// Create service
IService service = Services.Create(NetAccessorHandlers.Instance);
// Create container target
IContainerTarget target = new NetList(typeof(List<int>));
// Create request
IRequestFor<IListAccessor> request = new ListAccessorRequest
{
Constructor = new ConstructorRequest(target),
Deconstructor = new DeconstructorRequest(target),
DefaultConstructor = new DefaultConstructorRequest(target),
Add = new AddRequest(target),
Insert = new InsertRequest(target),
RemoveAt = new RemoveAtRequest(target),
Get = new GetRequest(target),
Set = new SetRequest(target),
IndexOf = new IndexOfRequest(target),
Clear = new ClearRequest(target),
Count = new CountRequest(target),
IsAssigned = new IsAssignedRequest(target),
Unassign = new UnassignRequest(target),
ContainerType = new ContainerTypeRequest(target),
ElementType = new ElementTypeRequest(target),
Referer = new RefererRequest(target)
};
// Issue request
IListAccessor<List<int>, int> accessor = service.GetRequired<IRequest, IListAccessor<List<int>, int>>(request);
Accessor can be acquired from Microsoft's dependency injection implementation.
// Create service collection
IServiceCollection serviceCollection = new ServiceCollection()
.AddAvalancheService()
.AddHandlers(NetAccessorHandlers.Instance)
.AddCachePolicy(CachePolicies.Default);
// Add accessor support
serviceCollection.AddRange(AccessorServiceDescriptors.Instance);
// Create service provider
IServiceProvider service = serviceCollection.BuildServiceProvider();
// Create accessor
IListAccessor<List<int>, int> accessor = service.GetRequiredService<IListAccessor<List<int>, int>>();
If dependency injection is used, ListAccessorRequest can be issued with service request to IListAccessor<L>.
// Create service
IServiceProvider service = Services.Create(NetAccessorHandlers.Instance);
// Create accessor
IListAccessor<List<int>, int> accessor = service.GetRequiredService<IListAccessor<List<int>, int>>();
Usage
.DefaultConstructor creates a list with default value.
List<int> list = accessor.DefaultConstructor.Read();
.Constructor creates a list from enumerable of elements.
List<int> list = accessor.Constructor.ReadAs<IEnumerable<int>, List<int>>(new int[] { 1, 2, 3 });
.Deconstructor reads values as an enumerable.
List<int> myList = new List<int> { 7, 8, 9 };
IEnumerable<int> deconstruction = accessor.Deconstructor.ReadAs<List<int>, IEnumerable<int>>(myList);
.Add adds an element.
List<int> myList = new List<int>();
accessor.Add.Write(10, myList);
.Insert inserts an element.
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Insert element to list
accessor.Insert.Write((100, 1L), list);
.RemoveAt removes an element at index.
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Remove at index
accessor.RemoveAt.Write(0L, list);
.Get reads an element at index.
List<int> list = new List<int> { 1, 2, 3 };
int value = accessor.Get.Read((list, 0L));
.Set assigns an element at index.
List<int> list = new List<int> { 1, 2, 3 };
accessor.Set.Write((10, 0L), list);
.IndexOf searches for an element.
List<int> list = new List<int> { 1, 2, 3 };
long index = accessor.IndexOf.Read((list, 2));
.Clear removes all elements.
List<int> list = new List<int> { 1, 2, 3 };
accessor.Clear.Write(default, list);
.Count returns the number of elements.
List<int> list = new List<int> { 1, 2, 3 };
long count = accessor.Count.Read(list);
.IsAssigned tests whether a list is assigned in container.
List<int> list = new List<int> { 1, 2, 3 };
bool nonNull = accessor.IsAssigned.Read(list);
.Unassign removes list at container.
List<int> list = new List<int> { 1, 2, 3 };
accessor.Unassign.Write(default, ref list);
Notes
A ref must be used when accessing value-typed container.
// Create accessor
IListAccessor<StructList4<int>, int> accessor =
Services.Create(NetAccessorHandlers.Instance)
.GetRequiredService<IListAccessor<StructList4<int>, int>>();
// Create value-typed list into stack
var list = new StructList4<int> { 1, 2, 3 };
// Add an element into value-typed list in stack
accessor.Add.Write(4, ref list);
Boxed value-types can be accessed as object.
// Create accessor
IListAccessor<StructList4<int>, int> accessor =
Services.Create(NetAccessorHandlers.Instance)
.GetRequiredService<IListAccessor<StructList4<int>, int>>();
// Create value-typed list into heap
object list = new StructList4<int> { 1, 2, 3 };
// Add an element into value-typed list in heap
accessor.Add.TypeCast<int, object>().Write(4, list);
Writers
Writers for IList<> types can be constructed separately without IService.
ListConstructor.Create(type) creates constructor for any IList<>.
var constructor = (IWriterToRef<IEnumerable<int>, List<int>>) ListConstructor.Create(typeof(List<int>));
int[] initialValues = new[] { 1, 2, 3 };
List<int> list = constructor.Read(initialValues);
Constructor can be adapted from a delegate.
var constructor = DelegateWriter.Reader((IEnumerable<int> enumr) => new List<int>(enumr));
int[] initialValues = new[] { 1, 2, 3 };
List<int> list = constructor.Read(initialValues);
ListDeconstructor.Create(type) creates deconstructor for any IList<>.
var deconstructor = (IWriterToRef<List<int>, IEnumerable<int>>) ListDeconstructor.Create(typeof(List<int>));
List<int> list = new List<int> { 1, 2, 3 };
IEnumerable<int> enumr = deconstructor.Read(list);
Deconstructor can be adapted from a delegate.
var deconstructor = DelegateWriter.Reader<List<int>, IEnumerable<int>>((List<int> list) => list.ToArray());
List<int> list = new List<int> { 1, 2, 3 };
IEnumerable<int> enumr = deconstructor.Read(list);
DefaultConstructor.Create(type) creates default instance for types that have a no parameter constructor.
var defaultConstructor = (IWriterToRef<Avalanche.Void, List<int>>) DefaultConstructor.Create(typeof(List<int>));
List<int> list = defaultConstructor.Read();
DefaultConstructor can be adapted from a delegate.
var listDefaultConstructor = DelegateWriter.Reader<Avalanche.Void, List<int>>(@void => new List<int>());
var arrayDefaultConstructor = DelegateWriter.Reader<Avalanche.Void, int[]>(@void => Array.Empty<int>());
List<int> list = listDefaultConstructor.Read();
int[] array = arrayDefaultConstructor.Read();
ListAdd.Create(listType, elementType) creates adder.
var listAdd = (IWriter<int, List<int>>)ListAdd.Create(typeof(List<int>));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Add element to list
listAdd.WriteAs(100, list);
To write to value-typed list on stack ref is used.
// Create writer
IWriter listAdd = ListAdd.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object listBox = list;
// Add element to the list in heap
listAdd.TypeCast<int, object>().Write(100, listBox);
// Copy from heap
list = (StructList4<int>)listBox;
// Print
WriteLine(list[3]); // 100
To write to value-typed list in heap object is used.
// Create writer
IWriterBase<int, StructList4<int>> listAdd = (IWriterBase<int, StructList4<int>>)ListAdd.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Add
listAdd.Write(100, ref list);
// Print
WriteLine(list[3]); // 100
List adder can be adapted from delegate.
var listAdd = DelegateWriter.Writer((int value, List<int> list) => list.Add(value));
List<int> list = new List<int> { 1, 2, 3 };
listAdd.Write(4, list);
ListInsert.Create(listType, elementType) creates inserter.
var listInsert = (IWriter<(int, long), List<int>>)ListInsert.Create(typeof(List<int>));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Insert element to list
listInsert.WriteAs((100, 1L), list);
List inserter be adapted from delegate.
var listInsert = (IWriter<(int, long), List<int>>)
DelegateWriter.Writer(
((int value, long index) args, List<int> list) => list.Insert((int)args.index, args.value));
List<int> list = new List<int> { 1, 2, 3 };
listInsert.WriteAs((100, 1L), list);
ListRemoveAt.Create(listType, elementType) creates element remover.
var listRemoveAt = (IWriterBase<long, List<int>>) ListRemoveAt.Create(typeof(List<int>), typeof(int));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Remove at index
listRemoveAt.Write(0L, list);
List element remover can be adapted from delegate.
var listRemoveAt = DelegateWriter.Writer((long value, List<int> list) => list.RemoveAt((int)value));
List<int> list = new List<int> { 1, 2, 3 };
listRemoveAt.Write(0L, list);
ListGet.Create(listType, elementType) creates getter.
var listGet = (IWriterToRef<(List<int>, long), int>)ListGet.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
List getter can be adapted from delegate.
var listGet = DelegateWriter.Reader<(List<int>, long), int>(args => args.Item1[(int)args.Item2]);
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
ListSet.Create(listType, elementType) creates setter.
var listSet = (IWriter<(int, long), List<int>>)ListSet.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
listSet.Write((10, 0L), list);
List setter can be adapted from delegate.
IWriter<(int, long), List<int>> listSet =
DelegateWriter.Writer<(int, long), List<int>>(((int value, long index) args, List<int> list) => list[(int)args.index] = args.value);
List<int> list = new List<int> { 1, 2, 3 };
listSet.Write((10, 0L), list);
ListClear.Create(listType, elementType) creates list element clearer.
IWriter<Avalanche.Void, List<int>> listClear =
(IWriter<Avalanche.Void, List<int>>)
ListClear.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
listClear.Write(default, list);
List clearer can be adapted from delegate.
IWriter<Avalanche.Void, List<int>> listClear = DelegateWriter.Invoke<List<int>>(list => list.Clear());
List<int> list = new List<int> { 1, 2, 3 };
listClear.Write(default, list);
ListCount.Create(listType, elementType) creates list element counter.
var listCount = (IWriterToRef<List<int>, long>) ListCount.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
long count = listCount.Read(list);
List counter can be adapted from delegate.
IWriterToRef<List<int>, long> listCount =
DelegateWriter.Reader<List<int>, long>(list => list.Count);
List<int> list = new List<int> { 1, 2, 3 };
long count = listCount.Read(list);
ListReferer.Create(listType, elementType) creates list element referer.
// Create referer
IReferer<(List<int>, long), int> referer = (IReferer<(List<int>, long), int>)ListReferer.Create(typeof(List<int>));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Get pointer to list[2]
ref int elementReference = ref referer.GetReference((list, 2));
// Write
elementReference = 100;
// Print
WriteLine(list[2]); // 100
ListReferer works on arrays as well.
// Create referer
IReferer<(List<int>, long), int> referer = (IReferer<(List<int>, long), int>)ListReferer.Create(typeof(List<int>));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Get pointer to list[2]
ref int elementReference = ref referer.GetReference((list, 2));
// Write
elementReference = 100;
// Print
WriteLine(list[2]); // 100
RefererRequest queries referer from service.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, AccessorHandlers.Instance, NetAccessorHandlers.Instance), CachePolicies.Default);
// Create request
IRequest request = new RefererRequest(new NetList(typeof(List<int>)));
// Create referer
IReferer<(List<int>, long), int> referer = service.GetRequired<IRequest, IReferer<(List<int>, long), int>>(request);
// 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]);
IsAssigned.Create(type) creates default assignment tester.
var isAssigned = (IWriterToRef<List<int>, bool>)IsAssigned.Create(typeof(List<int>));
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
Assignment tester can be adapted from delegate.
IWriterToRef<List<int>, bool> isAssigned = DelegateWriter.Reader<List<int>, bool>(list => list is not null);
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
Unassign.Create(type) creates conteiner nuller.
var isAssigned = (IWriterToRef<List<int>, bool>)IsAssigned.Create(typeof(List<int>));
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
Null assigner can be adapted from delegate.
IWriterToRef<List<int>, bool> isAssigned = DelegateWriter.Reader<List<int>, bool>(list => list is not null);
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
Full Example
Full example
using System;
using System.Collections.Generic;
using Avalanche.Accessor;
using Avalanche.DataType;
using Avalanche.Service;
using Avalanche.Utilities;
using Avalanche.Writer;
using Microsoft.Extensions.DependencyInjection;
using static System.Console;
public class ilist
{
public static void Run()
{
{
// <10>
// Create service
IService service = Services.Create(NetAccessorHandlers.Instance);
// Create container target
IContainerTarget target = new NetList(typeof(List<int>));
// Create request
IRequestFor<IAccessor> request = new AccessorRequest(target);
// Issue request
IListAccessor<List<int>, int> accessor = service.GetRequired<IRequest, IListAccessor<List<int>, int>>(request);
// </10>
}
{
// <11>
// Create service
IService service = Services.Create(NetAccessorHandlers.Instance);
// Create container target
IContainerTarget target = new NetList(typeof(List<int>));
// Create request
IRequestFor<IListAccessor> request = new ListAccessorRequest(target);
// Issue request
IListAccessor<List<int>, int> accessor = service.GetRequired<IRequest, IListAccessor<List<int>, int>>(request);
// </11>
}
{
// <12>
// Create service
IService service = Services.Create(NetAccessorHandlers.Instance);
// Create container target
IContainerTarget target = new NetList(typeof(List<int>));
// Create request
IRequestFor<IListAccessor> request = new ListAccessorRequest
{
Constructor = new ConstructorRequest(target),
Deconstructor = new DeconstructorRequest(target),
DefaultConstructor = new DefaultConstructorRequest(target),
Add = new AddRequest(target),
Insert = new InsertRequest(target),
RemoveAt = new RemoveAtRequest(target),
Get = new GetRequest(target),
Set = new SetRequest(target),
IndexOf = new IndexOfRequest(target),
Clear = new ClearRequest(target),
Count = new CountRequest(target),
IsAssigned = new IsAssignedRequest(target),
Unassign = new UnassignRequest(target),
ContainerType = new ContainerTypeRequest(target),
ElementType = new ElementTypeRequest(target),
Referer = new RefererRequest(target)
};
// Issue request
IListAccessor<List<int>, int> accessor = service.GetRequired<IRequest, IListAccessor<List<int>, int>>(request);
// </12>
}
{
// <13>
// Create service collection
IServiceCollection serviceCollection = new ServiceCollection()
.AddAvalancheService()
.AddHandlers(NetAccessorHandlers.Instance)
.AddCachePolicy(CachePolicies.Default);
// Add accessor support
serviceCollection.AddRange(AccessorServiceDescriptors.Instance);
// Create service provider
IServiceProvider service = serviceCollection.BuildServiceProvider();
// Create accessor
IListAccessor<List<int>, int> accessor = service.GetRequiredService<IListAccessor<List<int>, int>>();
// </13>
}
{
// <14>
// Create service
IServiceProvider service = Services.Create(NetAccessorHandlers.Instance);
// Create accessor
IListAccessor<List<int>, int> accessor = service.GetRequiredService<IListAccessor<List<int>, int>>();
// </14>
}
{
IListAccessor<List<int>, int> accessor = Services.Create(NetAccessorHandlers.Instance).GetRequiredService<IListAccessor<List<int>, int>>();
{
// <51>
List<int> list = accessor.DefaultConstructor.Read();
// </51>
}
{
// <52>
List<int> list = accessor.Constructor.ReadAs<IEnumerable<int>, List<int>>(new int[] { 1, 2, 3 });
// </52>
}
{
// <53>
List<int> myList = new List<int> { 7, 8, 9 };
IEnumerable<int> deconstruction = accessor.Deconstructor.ReadAs<List<int>, IEnumerable<int>>(myList);
// </53>
}
{
// <54>
List<int> myList = new List<int>();
accessor.Add.Write(10, myList);
// </54>
}
{
// <55>
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Insert element to list
accessor.Insert.Write((100, 1L), list);
// </55>
}
{
// <56>
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Remove at index
accessor.RemoveAt.Write(0L, list);
// </56>
}
{
// <57>
List<int> list = new List<int> { 1, 2, 3 };
int value = accessor.Get.Read((list, 0L));
// </57>
}
{
// <58>
List<int> list = new List<int> { 1, 2, 3 };
accessor.Set.Write((10, 0L), list);
// </58>
}
{
// <59>
List<int> list = new List<int> { 1, 2, 3 };
long index = accessor.IndexOf.Read((list, 2));
// </59>
}
{
// <60>
List<int> list = new List<int> { 1, 2, 3 };
accessor.Clear.Write(default, list);
// </60>
}
{
// <61>
List<int> list = new List<int> { 1, 2, 3 };
long count = accessor.Count.Read(list);
// </61>
}
{
// <62>
List<int> list = new List<int> { 1, 2, 3 };
bool nonNull = accessor.IsAssigned.Read(list);
// </62>
}
{
// <63>
List<int> list = new List<int> { 1, 2, 3 };
accessor.Unassign.Write(default, ref list);
// </63>
}
}
{
// <71>
// Create accessor
IListAccessor<StructList4<int>, int> accessor =
Services.Create(NetAccessorHandlers.Instance)
.GetRequiredService<IListAccessor<StructList4<int>, int>>();
// Create value-typed list into stack
var list = new StructList4<int> { 1, 2, 3 };
// Add an element into value-typed list in stack
accessor.Add.Write(4, ref list);
// </71>
}
{
// <72>
// Create accessor
IListAccessor<StructList4<int>, int> accessor =
Services.Create(NetAccessorHandlers.Instance)
.GetRequiredService<IListAccessor<StructList4<int>, int>>();
// Create value-typed list into heap
object list = new StructList4<int> { 1, 2, 3 };
// Add an element into value-typed list in heap
accessor.Add.TypeCast<int, object>().Write(4, list);
// </72>
}
// 81: Constructor
{
#pragma warning disable CS0168
// <00>
IWriterToRef<IEnumerable<int>, List<int>> listConstructor;
// </00>
#pragma warning restore CS0168
}
{
// <81B>
var constructor = (IWriterToRef<IEnumerable<int>, List<int>>) ListConstructor.Create(typeof(List<int>));
int[] initialValues = new[] { 1, 2, 3 };
List<int> list = constructor.Read(initialValues);
// </81B>
}
// Value List on stack
{
// <81C>
// Create writer
IWriterToRef<IEnumerable<int>, StructList4<int>> listConstructor =
(IWriterToRef<IEnumerable<int>, StructList4<int>>)
ListConstructor.Create(typeof(StructList4<int>));
// Values
int[] values = new[] { 1, 2, 3 };
// Create list
StructList4<int> list = listConstructor.Read(values);
// </81C>
}
// Value List on heap
{
// <81D>
// Create writer
IWriterToRef<IEnumerable<int>, StructList4<int>> listConstructor =
(IWriterToRef<IEnumerable<int>, StructList4<int>>)
ListConstructor.Create(typeof(StructList4<int>));
// Cast
IWriterBase<IEnumerable<int>, object> listCtorAdapted =
listConstructor.TypeCast<IEnumerable<int>, object>();
// Values
int[] values = new[] { 1, 2, 3 };
// Create value-typed list inside heap box
object listBox = listCtorAdapted.Read(values);
// </81D>
}
{
// <81E>
var constructor = DelegateWriter.Reader((IEnumerable<int> enumr) => new List<int>(enumr));
int[] initialValues = new[] { 1, 2, 3 };
List<int> list = constructor.Read(initialValues);
// </81E>
}
{
// <81F>
IRequestFor<IWriter> request = new ConstructorRequest(new NetList(typeof(List<int>)));
IWriterToRef<IEnumerable<int>, List<int>> listConstructor =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<IRequest, IWriterToRef<IEnumerable<int>, List<int>>>(request);
int[] values = new[] { 1, 2, 3 };
List<int> list = listConstructor.Read(values);
// </81F>
}
// 82: Deconstructor
{
#pragma warning disable CS0168
// <00>
IWriterToRef<List<int>, IEnumerable<int>> listDeconstructor;
// </00>
#pragma warning restore CS0168
}
{
// <82B>
var deconstructor = (IWriterToRef<List<int>, IEnumerable<int>>) ListDeconstructor.Create(typeof(List<int>));
List<int> list = new List<int> { 1, 2, 3 };
IEnumerable<int> enumr = deconstructor.Read(list);
// </82B>
}
// Value List on stack
{
// <82C>
// Create writer
IWriterFromRefToRef<StructList4<int>, IEnumerable<int>> listDeconstructor =
(IWriterFromRefToRef<StructList4<int>, IEnumerable<int>>)
ListDeconstructor.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Deconstruct
IEnumerable<int> enumr = listDeconstructor.Read(ref list);
// </82C>
}
// Value List on heap
{
// <82D>
// Create writer
IWriterFromRefToRef<StructList4<int>, IEnumerable<int>> listDeconstructor =
(IWriterFromRefToRef<StructList4<int>, IEnumerable<int>>)
ListDeconstructor.Create(typeof(StructList4<int>));
// Cast
IWriterToRef<object, IEnumerable<int>> listCtorAdapted =
(IWriterToRef<object, IEnumerable<int>>)
listDeconstructor.TypeCast<object, IEnumerable<int>>();
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object box = list;
// Deconstruct from heap
IEnumerable<int> enumr = listCtorAdapted.Read(box);
// </82D>
}
{
// <82E>
var deconstructor = DelegateWriter.Reader<List<int>, IEnumerable<int>>((List<int> list) => list.ToArray());
List<int> list = new List<int> { 1, 2, 3 };
IEnumerable<int> enumr = deconstructor.Read(list);
// </82E>
}
// 83: DefaultConstructor
{
#pragma warning disable CS0168
// <83>
IWriterToRef<Avalanche.Void, List<int>> listDefaultConstructor;
IWriterToRef<Avalanche.Void, int[]> arrayDefaultConstructor;
// </83>
#pragma warning restore CS0168
}
{
// <83B>
var defaultConstructor = (IWriterToRef<Avalanche.Void, List<int>>) DefaultConstructor.Create(typeof(List<int>));
List<int> list = defaultConstructor.Read();
// </83B>
}
{
// <83E>
var listDefaultConstructor = DelegateWriter.Reader<Avalanche.Void, List<int>>(@void => new List<int>());
var arrayDefaultConstructor = DelegateWriter.Reader<Avalanche.Void, int[]>(@void => Array.Empty<int>());
List<int> list = listDefaultConstructor.Read();
int[] array = arrayDefaultConstructor.Read();
// </83E>
}
{
// <83F>
DefaultConstructorRequest request = new DefaultConstructorRequest(new NetList(typeof(List<int>)));
IWriterToRef<Avalanche.Void, List<int>> defaultConstructor =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<DefaultConstructorRequest, IWriterToRef<Avalanche.Void, List<int>>>(request);
// </83F>
}
// 84: Add
{
#pragma warning disable CS0168
// <84>
IWriterBase<int, List<int>> listAdd;
// </84>
#pragma warning restore CS0168
}
{
// <84B>
var listAdd = (IWriter<int, List<int>>)ListAdd.Create(typeof(List<int>));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Add element to list
listAdd.WriteAs(100, list);
// </84B>
}
// Value List on heap
{
// <84C>
// Create writer
IWriter listAdd = ListAdd.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object listBox = list;
// Add element to the list in heap
listAdd.TypeCast<int, object>().Write(100, listBox);
// Copy from heap
list = (StructList4<int>)listBox;
// Print
WriteLine(list[3]); // 100
// </84C>
}
// Value List on stack
{
// <84D>
// Create writer
IWriterBase<int, StructList4<int>> listAdd = (IWriterBase<int, StructList4<int>>)ListAdd.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Add
listAdd.Write(100, ref list);
// Print
WriteLine(list[3]); // 100
// </84D>
}
{
// <84E>
var listAdd = DelegateWriter.Writer((int value, List<int> list) => list.Add(value));
List<int> list = new List<int> { 1, 2, 3 };
listAdd.Write(4, list);
// </84E>
}
{
// <84F>
IRequestFor<IWriter> request = new AddRequest(new NetList(typeof(List<int>)));
IWriter<int, List<int>> listAdd = Services.Create(NetAccessorHandlers.Instance).GetRequired<IRequest, IWriter<int, List<int>>>(request);
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Add element to list
listAdd.Write(100, list);
// </84F>
}
// 85 : Insert
{
#pragma warning disable CS0168
// <85>
IWriter<(int, long), List<int>> listInsert;
// </85>
#pragma warning restore CS0168
}
{
// <85B>
var listInsert = (IWriter<(int, long), List<int>>)ListInsert.Create(typeof(List<int>));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Insert element to list
listInsert.WriteAs((100, 1L), list);
// </85B>
}
// Value List on stack
{
// <85C>
// Create writer
IWriterToRef<(int, long), StructList4<int>> listInsert =
(IWriterToRef<(int, long), StructList4<int>>)
ListInsert.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Insert
listInsert.Write((100, 1L), ref list);
// Print
WriteLine(list[1]); // 100
// </85C>
}
// Value List on heap
{
// <85D>
// Create writer
IWriterToRef<(int, long), StructList4<int>> listInsert =
(IWriterToRef<(int, long), StructList4<int>>)
ListInsert.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object listBox = list;
// Insert element to the list in heap
listInsert.TypeCast<(int, long), object>().Write((100, 1L), listBox);
// Copy from heap
list = (StructList4<int>)listBox;
// Print
WriteLine(list[1]); // 100
// </85D>
}
{
// <85E>
var listInsert = (IWriter<(int, long), List<int>>)
DelegateWriter.Writer(
((int value, long index) args, List<int> list) => list.Insert((int)args.index, args.value));
List<int> list = new List<int> { 1, 2, 3 };
listInsert.WriteAs((100, 1L), list);
// </85E>
}
{
// <85F>
IRequest request = new InsertRequest(new NetList(typeof(List<int>)));
IWriter<(int, long), List<int>> listInsert =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<IRequest, IWriter<(int, long), List<int>>>(request);
// </85F>
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Insert element to list
listInsert.WriteAs((100, 1L), list);
}
// 86: RemoveAt
{
#pragma warning disable CS0168
// <86>
IWriterBase<long, List<int>> listRemoveAt;
// </86>
#pragma warning restore CS0168
}
{
// <86B>
var listRemoveAt = (IWriterBase<long, List<int>>) ListRemoveAt.Create(typeof(List<int>), typeof(int));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Remove at index
listRemoveAt.Write(0L, list);
// </86B>
}
// Value List on stack
{
// <86C>
// Create writer
IWriterToRef<long, StructList4<int>> listRemoveAt =
(IWriterToRef<long, StructList4<int>>)
ListRemoveAt.Create(typeof(StructList4<int>), typeof(int));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Remove at
listRemoveAt.Write(0L, ref list);
// Print "2"
WriteLine(list[0]);
// </86C>
}
// Value List on heap
{
// <86D>
// Create writer
IWriterToRef<long, StructList4<int>> listRemoveAt =
(IWriterToRef<long, StructList4<int>>)
ListRemoveAt.Create(typeof(StructList4<int>), typeof(int));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object listBox = list;
// RemoveAt element to the list in heap
listRemoveAt.TypeCast<long, object>().Write(0L, listBox);
// Copy from heap
list = (StructList4<int>)listBox;
// Print "2"
WriteLine(list[0]);
// </86D>
}
{
// <86E>
var listRemoveAt = DelegateWriter.Writer((long value, List<int> list) => list.RemoveAt((int)value));
List<int> list = new List<int> { 1, 2, 3 };
listRemoveAt.Write(0L, list);
// </86E>
}
{
// <86F>
IRequestFor<IWriter> request = new RemoveAtRequest(new NetList(typeof(List<int>)));
IWriter<long, List<int>> listRemoveAt = Services.Create(NetAccessorHandlers.Instance).GetRequired<IRequest, IWriter<long, List<int>>>(request);
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// RemoveAt element to list
listRemoveAt.Write(0L, list);
// </86F>
}
// 87: Get
{
#pragma warning disable CS0168
// <87>
IWriterToRef<(List<int>, long), int> listGet;
// </87>
#pragma warning restore CS0168
}
{
// <87A>
IWriterToRef<(List<int>, long), int> listGet = new ListGet<List<int>, int>();
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
// </87A>
}
{
// <87B>
var listGet = (IWriterToRef<(List<int>, long), int>)ListGet.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
// </87B>
}
{
// <87E>
var listGet = DelegateWriter.Reader<(List<int>, long), int>(args => args.Item1[(int)args.Item2]);
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
// </87E>
}
{
// <87F>
GetRequest listRequest = new GetRequest(new NetList(typeof(List<int>)));
IWriterToRef<(List<int>, long), int> listGet =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<GetRequest, IWriterToRef<(List<int>, long), int>>(listRequest);
List<int> list = new List<int> { 1, 2, 3 };
int value = listGet.Read((list, 0L));
// </87F>
}
// 88: Set
{
#pragma warning disable CS0168
// <88>
IWriter<(int, long), List<int>> listSet;
// </88>
#pragma warning restore CS0168
}
{
// <88A>
IWriter<(int, long), List<int>> listSet = new ListSet<List<int>, int>();
List<int> list = new List<int> { 1, 2, 3 };
listSet.Write((10, 0L), list);
// </88A>
}
{
// <88B>
var listSet = (IWriter<(int, long), List<int>>)ListSet.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
listSet.Write((10, 0L), list);
// </88B>
}
{
// <88E>
IWriter<(int, long), List<int>> listSet =
DelegateWriter.Writer<(int, long), List<int>>(((int value, long index) args, List<int> list) => list[(int)args.index] = args.value);
List<int> list = new List<int> { 1, 2, 3 };
listSet.Write((10, 0L), list);
// </88E>
}
{
// <88F>
SetRequest listRequest = new SetRequest(new NetList(typeof(List<int>)));
IWriter<(int, long), List<int>> listSet =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<SetRequest, IWriter<(int, long), List<int>>>(listRequest);
List<int> list = new List<int> { 1, 2, 3 };
listSet.Write((10, 0L), list);
// </88F>
}
// 89: Clear
{
#pragma warning disable CS0168
// <89>
IWriter<Avalanche.Void, List<int>> listClear;
// </89>
#pragma warning restore CS0168
}
{
// <89A>
IWriter<Avalanche.Void, List<int>> listClear = new ListClear<List<int>, int>();
List<int> list = new List<int> { 1, 2, 3 };
listClear.Write(default, list);
// </89A>
}
{
// <89B>
IWriter<Avalanche.Void, List<int>> listClear =
(IWriter<Avalanche.Void, List<int>>)
ListClear.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
listClear.Write(default, list);
// </89B>
}
// Value List on stack
{
// <89C>
// Create writer
IWriterToRef<Avalanche.Void, StructList4<int>> listClear =
(IWriterToRef<Avalanche.Void, StructList4<int>>)
ListClear.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Clear list
listClear.Write(default, ref list);
// </89C>
}
// Value List on heap
{
// <89D>
// Create writer
IWriterToRef<Avalanche.Void, StructList4<int>> listClear =
(IWriterToRef<Avalanche.Void, StructList4<int>>)
ListClear.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object box = list;
// Clear list
listClear.TypeCast<Avalanche.Void, object>().Write(default, box);
// </89D>
}
{
// <89E>
IWriter<Avalanche.Void, List<int>> listClear = DelegateWriter.Invoke<List<int>>(list => list.Clear());
List<int> list = new List<int> { 1, 2, 3 };
listClear.Write(default, list);
// </89E>
}
{
// <89F>
ClearRequest listRequest = new ClearRequest(new NetList(typeof(List<int>)));
IWriter<Avalanche.Void, List<int>> listClear =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<ClearRequest, IWriter<Avalanche.Void, List<int>>>(listRequest);
List<int> list = new List<int> { 1, 2, 3 };
listClear.Write(default, list);
// </89F>
}
// 90: Count
{
#pragma warning disable CS0168
// <90>
IWriterToRef<List<int>, long> listCount;
// </90>
#pragma warning restore CS0168
}
{
// <90A>
IWriterToRef<List<int>, long> listCount = new ListCount<List<int>, int>();
List<int> list = new List<int> { 1, 2, 3 };
long count = listCount.Read(list);
// </90A>
}
{
// <90B>
var listCount = (IWriterToRef<List<int>, long>) ListCount.Create(typeof(List<int>), typeof(int));
List<int> list = new List<int> { 1, 2, 3 };
long count = listCount.Read(list);
// </90B>
}
// Value List on stack
{
// <90C>
// Create writer
IWriterFromRefToRef<StructList4<int>, long> listCount =
(IWriterFromRefToRef<StructList4<int>, long>)
ListCount.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Get count
long count = listCount.Read(ref list);
// </90C>
}
// Value List on heap
{
// <90D>
// Create writer
IWriterFromRefToRef<StructList4<int>, long> listCount =
(IWriterFromRefToRef<StructList4<int>, long>)
ListCount.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object box = list;
// Get count from value-typed list in heap
long count = listCount.TypeCast<object, long>().Read(box);
// </90D>
}
{
// <90E>
IWriterToRef<List<int>, long> listCount =
DelegateWriter.Reader<List<int>, long>(list => list.Count);
List<int> list = new List<int> { 1, 2, 3 };
long count = listCount.Read(list);
// </90E>
}
{
// <90F>
CountRequest listRequest = new CountRequest(new NetList(typeof(List<int>)));
IWriterToRef<List<int>, long> listCount =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<CountRequest, IWriterToRef<List<int>, long>>(listRequest);
List<int> list = new List<int> { 1, 2, 3 };
long count = listCount.Read(list);
// </90F>
}
// 91: Referer
{
// <91A>
// Create referer
IReferer<(List<int>, long), int> referer = (IReferer<(List<int>, long), int>)ListReferer.Create(typeof(List<int>));
// Create list
List<int> list = new List<int> { 1, 2, 3 };
// Get pointer to list[2]
ref int elementReference = ref referer.GetReference((list, 2));
// Write
elementReference = 100;
// Print
WriteLine(list[2]); // 100
// </91A>
}
{
// <91B>
// Create referer
IReferer<(int[], long), int> referer = (IReferer<(int[], long), int>)ListReferer.Create(typeof(int[]));
// Create array
int[] array = new int[] { 4, 5, 6 };
// Get pointer to array[2]
ref int elementReference = ref referer.GetReference((array, 2));
// Write
elementReference = 100;
// Print
WriteLine(array[2]); // 100
// </91B>
}
{
// <91C>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, AccessorHandlers.Instance, NetAccessorHandlers.Instance), CachePolicies.Default);
// Create request
IRequest request = new RefererRequest(new NetList(typeof(List<int>)));
// Create referer
IReferer<(List<int>, long), int> referer = service.GetRequired<IRequest, IReferer<(List<int>, long), int>>(request);
// 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]);
// </91C>
}
// 98: IsAssigned
{
// <98A>
IWriterToRef<List<int>, bool> isAssigned = new IsAssigned<List<int>>();
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
// </98A>
}
{
// <98B>
var isAssigned = (IWriterToRef<List<int>, bool>)IsAssigned.Create(typeof(List<int>));
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
// </98B>
}
// Value List on stack
{
// <98C>
// Create writer
var isAssigned = (IWriterFromRefToRef<StructList4<int>, bool>) IsAssigned.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Test assignment
bool assigned = isAssigned.Read(ref list);
// </98C>
}
// Value List on heap
{
// <98D>
// Create writer
var isAssigned = (IWriterFromRefToRef<StructList4<int>, bool>) IsAssigned.Create(typeof(StructList4<int>));
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Copy to heap
object box = list;
// Test assignment
bool assigned = isAssigned.TypeCast<object, bool>().Read(list);
// </98D>
}
{
// <98E>
IWriterToRef<List<int>, bool> isAssigned = DelegateWriter.Reader<List<int>, bool>(list => list is not null);
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
// </98E>
}
{
// <98F>
IsAssignedRequest isAssignedRequest = new IsAssignedRequest(new NetList(typeof(List<int>)));
IWriterToRef<List<int>, bool> isAssigned =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<IsAssignedRequest, IWriterToRef<List<int>, bool>>(isAssignedRequest);
List<int> list = new List<int> { 1, 2, 3 };
bool assigned = isAssigned.Read(list);
// </98F>
}
// 99: Unassign
{
// <99A>
IWriterToRef<Avalanche.Void, List<int>> unassign = new Unassign<List<int>>();
List<int> list = new List<int> { 1, 2, 3 };
unassign.Write(default, ref list);
// </99A>
}
{
// <99B>
var unassign = (IWriterToRef<Avalanche.Void, List<int>>)Unassign.Create(typeof(List<int>));
List<int> list = new List<int> { 1, 2, 3 };
unassign.Write(default, ref list);
// </99B>
}
// Value List on stack
{
// <99C>
// Create writer
var unassign = new Unassign<StructList4<int>>();
// Create list
StructList4<int> list = new StructList4<int> { 1, 2, 3 };
// Unassign
unassign.Write(default, ref list);
// </99C>
}
// Value List on heap
{
// <99D>
// Create writer
var unassign = new Unassign<StructList4<int>>();
// Create list
object list = new StructList4<int> { 1, 2, 3 };
// Unassign
unassign.TypeCast<Avalanche.Void, object>().Write(default, ref list);
// </99D>
}
{
// <99E>
IWriterToRef<Avalanche.Void, List<int>> unassign = DelegateWriter.Writer((Avalanche.Void @void, ref List<int> list) => list = null!);
List<int> list = new List<int> { 1, 2, 3 };
unassign.Write(default, ref list);
// </99E>
}
{
// <99F>
UnassignRequest unassignRequest = new UnassignRequest(new NetList(typeof(List<int>)));
IWriterToRef<Avalanche.Void, List<int>> unassign =
Services.Create(NetAccessorHandlers.Instance)
.GetRequired<UnassignRequest, IWriterToRef<Avalanche.Void, List<int>>>(unassignRequest);
List<int> list = new List<int> { 1, 2, 3 };
unassign.Write(default, ref list);
// </99F>
}
}
}