MapConstructor
Map constructor implements IWriterToRef<IEnumerable<KeyValuePair<Key, Value>>, Map>.
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor;
MapConstructor.Create(type) creates constructor.
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor =
(IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>>)
MapConstructor.Create(typeof(Dictionary<string, int>));
Writer constructors a map.
KeyValuePair<string, int>[] values = new[] { new KeyValuePair<string, int>("A", 1), new KeyValuePair<string, int>("B", 2), new KeyValuePair<string, int>("C", 3) };
Dictionary<string, int> map = mapConstructor.Read(values);
Delegate can be adapted to writer.
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor = DelegateWriter.Reader((IEnumerable<KeyValuePair<string, int>> enumr) => new Dictionary<string, int>(enumr));
MapConstructorRequest is request to create constructor.
IRequestFor<IWriterBase> request = new MapConstructorRequest(typeof(Dictionary<string, int>));
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor =
AccessorServices.Instance
.GetRequired<IRequest, IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>>>(request);
Full Example
Full example
using System.Collections.Generic;
using Avalanche.Accessor;
using Avalanche.Accessor.Map;
using Avalanche.Service;
using Avalanche.Writer;
class mapconstructor
{
public static void Run()
{
{
#pragma warning disable CS0168
// <00>
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor;
// </00>
#pragma warning restore CS0168
}
{
// <01>
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor =
(IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>>)
MapConstructor.Create(typeof(Dictionary<string, int>));
// </01>
// <02>
KeyValuePair<string, int>[] values = new[] { new KeyValuePair<string, int>("A", 1), new KeyValuePair<string, int>("B", 2), new KeyValuePair<string, int>("C", 3) };
Dictionary<string, int> map = mapConstructor.Read(values);
// </02>
}
{
// <03>
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor = DelegateWriter.Reader((IEnumerable<KeyValuePair<string, int>> enumr) => new Dictionary<string, int>(enumr));
// </03>
KeyValuePair<string, int>[] values = new[] { new KeyValuePair<string, int>("A", 1), new KeyValuePair<string, int>("B", 2), new KeyValuePair<string, int>("C", 3) };
Dictionary<string, int> map = mapConstructor.Read(values);
}
{
// <11>
IRequestFor<IWriterBase> request = new MapConstructorRequest(typeof(Dictionary<string, int>));
IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>> mapConstructor =
AccessorServices.Instance
.GetRequired<IRequest, IWriterToRef<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>>>(request);
// </11>
KeyValuePair<string, int>[] values = new[] { new KeyValuePair<string, int>("A", 1), new KeyValuePair<string, int>("B", 2), new KeyValuePair<string, int>("C", 3) };
Dictionary<string, int> map = mapConstructor.Read(values);
}
}
}