public static void Translate <T, L>( this ITranslator translator, ref IList <T> list, NodePacketValueFactory <T> valueFactory, NodePacketCollectionCreator <L> collectionFactory) where L : IList <T> where T : ITranslatable { translator.Translate(ref list, AdaptFactory(valueFactory), collectionFactory); }
public static void TranslateDictionary <D, T>( this ITranslator translator, ref D dictionary, NodePacketValueFactory <T> valueFactory, NodePacketCollectionCreator <D> collectionCreator) where D : IDictionary <string, T> where T : class, ITranslatable { translator.TranslateDictionary(ref dictionary, AdaptFactory(valueFactory), collectionCreator); }
public static void TranslateHashSet <T>( this ITranslator translator, ref HashSet <T> hashSet, NodePacketValueFactory <T> valueFactory, NodePacketCollectionCreator <HashSet <T> > collectionFactory) where T : class, ITranslatable { if (!translator.TranslateNullable(hashSet)) { return; } int count = default; if (translator.Mode == TranslationDirection.WriteToStream) { count = hashSet.Count; } translator.Translate(ref count); if (translator.Mode == TranslationDirection.ReadFromStream) { hashSet = collectionFactory(count); for (int i = 0; i < count; i++) { T value = default; translator.Translate(ref value, valueFactory); hashSet.Add(value); } } if (translator.Mode == TranslationDirection.WriteToStream) { foreach (T item in hashSet) { T value = item; translator.Translate(ref value, valueFactory); } } }
public void TranslateDictionary <K, V>( ref IDictionary <K, V> dictionary, Translator <K> keyTranslator, Translator <V> valueTranslator, NodePacketCollectionCreator <IDictionary <K, V> > collectionCreator) { if (!TranslateNullable(dictionary)) { return; } int count = dictionary.Count; _writer.Write(count); foreach (KeyValuePair <K, V> pair in dictionary) { K key = pair.Key; keyTranslator.Invoke(ref key, this); V value = pair.Value; valueTranslator.Invoke(ref value, this); } }
public void TranslateDictionary <K, V>( ref IDictionary <K, V> dictionary, Translator <K> keyTranslator, Translator <V> valueTranslator, NodePacketCollectionCreator <IDictionary <K, V> > dictionaryCreator) { if (!TranslateNullable(dictionary)) { return; } int count = _reader.ReadInt32(); dictionary = dictionaryCreator(count); for (int i = 0; i < count; i++) { K key = default(K); keyTranslator.Invoke(ref key, this); V value = default(V); valueTranslator(ref value, this); dictionary[key] = value; } }
/// <summary> /// Translates a list of T where T implements INodePacketTranslateable /// </summary> /// <param name="list">The list to be translated.</param> /// <param name="factory">factory to create type T</param> /// <param name="collectionFactory">factory to create the IList</param> /// <typeparam name="T">A TaskItemType</typeparam> /// <typeparam name="L">IList subtype</typeparam> public void Translate <T, L>(ref IList <T> list, NodePacketValueFactory <T> factory, NodePacketCollectionCreator <L> collectionFactory) where T : INodePacketTranslatable where L : IList <T> { if (!TranslateNullable(list)) { return; } int count = list.Count; _writer.Write(count); for (int i = 0; i < count; i++) { T value = list[i]; Translate <T>(ref value, factory); } }
/// <summary> /// Translates a dictionary of { string, T } for dictionaries with public parameterless constructors. /// </summary> /// <typeparam name="D">The reference type for the dictionary.</typeparam> /// <typeparam name="T">The reference type for values in the dictionary.</typeparam> /// <param name="dictionary">The dictionary to be translated.</param> /// <param name="valueFactory">The factory used to instantiate values in the dictionary.</param> /// <param name="dictionaryCreator">The delegate used to instantiate the dictionary.</param> public void TranslateDictionary <D, T>(ref D dictionary, NodePacketValueFactory <T> valueFactory, NodePacketCollectionCreator <D> dictionaryCreator) where D : IDictionary <string, T> where T : class, INodePacketTranslatable { if (!TranslateNullable(dictionary)) { return; } int count = _reader.ReadInt32(); dictionary = dictionaryCreator(count); for (int i = 0; i < count; i++) { string key = null; Translate(ref key); T value = null; Translate(ref value, valueFactory); dictionary[key] = value; } }
public void TranslateDictionary(ref IDictionary <string, string> dictionary, NodePacketCollectionCreator <IDictionary <string, string> > dictionaryCreator) { if (!TranslateNullable(dictionary)) { return; } int count = _reader.ReadInt32(); dictionary = dictionaryCreator(count); for (int i = 0; i < count; i++) { string key = null; Translate(ref key); string value = null; Translate(ref value); dictionary[key] = value; } }
public void Translate <T, L>(ref IList <T> list, NodePacketValueFactory <T> factory, NodePacketCollectionCreator <L> collectionFactory) where T : INodePacketTranslatable where L : IList <T> { if (!TranslateNullable(list)) { return; } int count = _reader.ReadInt32(); list = collectionFactory(count); for (int i = 0; i < count; i++) { T value = default(T); if (!TranslateNullable(value)) { continue; } value = factory(this); list.Add(value); } }
/// <summary> /// Translates a dictionary of { string, T } for dictionaries with public parameterless constructors. /// </summary> /// <typeparam name="D">The reference type for the dictionary.</typeparam> /// <typeparam name="T">The reference type for values in the dictionary.</typeparam> /// <param name="dictionary">The dictionary to be translated.</param> /// <param name="valueFactory">The factory used to instantiate values in the dictionary.</param> /// <param name="dictionaryCreator">The delegate used to instantiate the dictionary.</param> public void TranslateDictionary <D, T>(ref D dictionary, NodePacketValueFactory <T> valueFactory, NodePacketCollectionCreator <D> dictionaryCreator) where D : IDictionary <string, T> where T : class, INodePacketTranslatable { if (!TranslateNullable(dictionary)) { return; } int count = dictionary.Count; _writer.Write(count); foreach (KeyValuePair <string, T> pair in dictionary) { string key = pair.Key; Translate(ref key); T value = pair.Value; Translate(ref value, valueFactory); } }
public void TranslateDictionary(ref IDictionary <string, string> dictionary, NodePacketCollectionCreator <IDictionary <string, string> > dictionaryCreator) { if (!TranslateNullable(dictionary)) { return; } int count = dictionary.Count; _writer.Write(count); foreach (KeyValuePair <string, string> pair in dictionary) { string key = pair.Key; Translate(ref key); string value = pair.Value; Translate(ref value); } }
/// <summary> /// Translates a collection of T into the specified type using an <see cref="ObjectTranslator{T}"/> and <see cref="NodePacketCollectionCreator{L}"/> /// </summary> /// <param name="collection">The collection to be translated.</param> /// <param name="objectTranslator">The translator to use for the values in the collection.</param> /// <param name="collectionFactory">The factory to create the ICollection.</param> /// <typeparam name="T">The type contained in the collection.</typeparam> /// <typeparam name="L">The type of collection to be created.</typeparam> public void Translate <T, L>(ref ICollection <T> collection, ObjectTranslator <T> objectTranslator, NodePacketCollectionCreator <L> collectionFactory) where L : ICollection <T> { if (!TranslateNullable(collection)) { return; } _writer.Write(collection.Count); foreach (T item in collection) { T value = item; objectTranslator(this, ref value); } }
/// <summary> /// Translates a list of T using an <see cref="ObjectTranslator{T}"/> /// </summary> /// <param name="list">The list to be translated.</param> /// <param name="objectTranslator">The translator to use for the items in the list</param> /// <param name="collectionFactory">factory to create the IList</param> /// <typeparam name="T">A TaskItemType</typeparam> /// <typeparam name="L">IList subtype</typeparam> public void Translate <T, L>(ref IList <T> list, ObjectTranslator <T> objectTranslator, NodePacketCollectionCreator <L> collectionFactory) where L : IList <T> { if (!TranslateNullable(list)) { return; } int count = list.Count; _writer.Write(count); for (int i = 0; i < count; i++) { T value = list[i]; objectTranslator(this, ref value); } }
/// <summary> /// Translates a collection of T into the specified type using an <see cref="ObjectTranslator{T}"/> and <see cref="NodePacketCollectionCreator{L}"/> /// </summary> /// <param name="collection">The collection to be translated.</param> /// <param name="objectTranslator">The translator to use for the values in the collection.</param> /// <param name="collectionFactory">The factory to create the ICollection.</param> /// <typeparam name="T">The type contained in the collection.</typeparam> /// <typeparam name="L">The type of collection to be created.</typeparam> public void Translate <T, L>(ref ICollection <T> collection, ObjectTranslator <T> objectTranslator, NodePacketCollectionCreator <L> collectionFactory) where L : ICollection <T> { if (!TranslateNullable(collection)) { return; } int count = _reader.ReadInt32(); collection = collectionFactory(count); for (int i = 0; i < count; i++) { T value = default(T); objectTranslator(this, ref value); collection.Add(value); } }