Ejemplo n.º 1
0
            /// <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, NodePacketDictionaryCreator <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;
                }
            }
Ejemplo n.º 2
0
            /// <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, NodePacketDictionaryCreator <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);
                }
            }