Ejemplo n.º 1
0
        /// <summary>
        /// Adds specified string to String heap, if it's not there already.
        /// </summary>
        /// <param name="value">Array containing the blob.</param>
        /// <returns>Handle to the added or existing blob.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
        public StringHandle GetOrAddString(string value)
        {
            if (value == null)
            {
                Throw.ArgumentNull(nameof(value));
            }

            StringHandle handle;

            if (value.Length == 0)
            {
                handle = default(StringHandle);
            }
            else if (!_strings.TryGetValue(value, out handle))
            {
                handle = StringHandle.FromWriterVirtualIndex(_strings.Count + 1); // idx 0 is reserved for empty string
                _strings.Add(value, handle);
            }

            return(handle);
        }