/// <summary>
        /// Inner GetOrAdd for a collection.
        /// This method adds new metric collection type information for new collections as part of the same transaction.
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        private async Task <ConditionalValue <IReliableState> > TryCreateOrGetMetricReliableCollectionAsync(ITransaction tx, Type type, Uri name, TimeSpan timeout)
        {
            if (type.GetGenericTypeDefinition() == typeof(IReliableDictionary <,>))
            {
                // Store the given type information for the collection with the given name.
                // The type information is used to recreate the collection during enumeration.
                IReliableDictionary <string, string> metricDictionaryTypes = await this.GetTypeNameDictionaryAsync();

                if (!(await metricDictionaryTypes.ContainsKeyAsync(tx, name.ToString(), LockMode.Update)))
                {
                    await metricDictionaryTypes.AddAsync(tx, name.ToString(), type.AssemblyQualifiedName);
                }

                IReliableDictionary <BinaryValue, BinaryValue> innerStore =
                    await this.stateManagerReplica.GetOrAddAsync <IReliableDictionary <BinaryValue, BinaryValue> >(tx, name, timeout);

                return(new ConditionalValue <IReliableState>(
                           true,
                           MetricReliableDictionaryActivator.CreateFromReliableDictionaryType(
                               type,
                               innerStore,
                               new BinaryValueConverter(name, this.serializerResolver),
                               this.config)));
            }

            return(new ConditionalValue <IReliableState>(false, null));
        }
        /// <summary>
        /// Inner Get for a collection.
        /// This method only attemps to get existing collections.
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private async Task <ConditionalValue <IReliableState> > TryGetMetricReliableCollectionAsync(ITransaction tx, Type type, Uri name)
        {
            if (type.GetGenericTypeDefinition() == typeof(IReliableDictionary <,>))
            {
                ConditionalValue <IReliableDictionary <BinaryValue, BinaryValue> > tryGetResult =
                    await this.stateManagerReplica.TryGetAsync <IReliableDictionary <BinaryValue, BinaryValue> >(name);

                if (tryGetResult.HasValue)
                {
                    ConditionalValue <IReliableState> result = new ConditionalValue <IReliableState>(
                        true,
                        MetricReliableDictionaryActivator.CreateFromReliableDictionaryType(
                            type,
                            tryGetResult.Value,
                            new BinaryValueConverter(name, this.serializerResolver),
                            this.config));

                    return(result);
                }
            }

            return(new ConditionalValue <IReliableState>(false, null));
        }