Пример #1
0
        /// <summary>
        /// Merge newly sent field metadatas into existing ones.
        /// </summary>
        /// <param name="newMap">New field metadatas map.</param>
        public void Merge(IDictionary <int, Tuple <string, int> > newMap)
        {
            _saved = true;

            if (newMap == null || newMap.Count == 0)
            {
                return;
            }

            lock (this)
            {
                // 1. Create copies of the old meta.
                ICollection <int>    ids0  = _ids;
                PortableMetadataImpl meta0 = _meta;

                ICollection <int> newIds = ids0 != null ? new HashSet <int>(ids0) : new HashSet <int>();

                IDictionary <string, int> newFields = meta0 != null ?
                                                      new Dictionary <string, int>(meta0.FieldsMap()) : new Dictionary <string, int>(newMap.Count);

                // 2. Add new fields.
                foreach (KeyValuePair <int, Tuple <string, int> > newEntry in newMap)
                {
                    if (!newIds.Contains(newEntry.Key))
                    {
                        newIds.Add(newEntry.Key);
                    }

                    if (!newFields.ContainsKey(newEntry.Value.Item1))
                    {
                        newFields[newEntry.Value.Item1] = newEntry.Value.Item2;
                    }
                }

                // 3. Assign new meta. Order is important here: meta must be assigned before field IDs.
                _meta = new PortableMetadataImpl(_typeId, _typeName, newFields, _affKeyFieldName);
                _ids  = newIds;
            }
        }
Пример #2
0
        /// <summary>
        /// Get current type metadata.
        /// </summary>
        /// <returns>Type metadata.</returns>
        public IPortableMetadata Metadata()
        {
            PortableMetadataImpl meta0 = _meta;

            return(meta0 != null ? _meta : _emptyMeta);
        }
        /// <summary>
        /// Merge newly sent field metadatas into existing ones.
        /// </summary>
        /// <param name="newMap">New field metadatas map.</param>
        public void Merge(IDictionary<int, Tuple<string, int>> newMap)
        {
            _saved = true;

            if (newMap == null || newMap.Count == 0)
                return;

            lock (this)
            {
                // 1. Create copies of the old meta.
                ICollection<int> ids0 = _ids;
                PortableMetadataImpl meta0 = _meta;

                ICollection<int> newIds = ids0 != null ? new HashSet<int>(ids0) : new HashSet<int>();

                IDictionary<string, int> newFields = meta0 != null ?
                    new Dictionary<string, int>(meta0.FieldsMap()) : new Dictionary<string, int>(newMap.Count);

                // 2. Add new fields.
                foreach (KeyValuePair<int, Tuple<string, int>> newEntry in newMap)
                {
                    if (!newIds.Contains(newEntry.Key))
                        newIds.Add(newEntry.Key);

                    if (!newFields.ContainsKey(newEntry.Value.Item1))
                        newFields[newEntry.Value.Item1] = newEntry.Value.Item2;
                }

                // 3. Assign new meta. Order is important here: meta must be assigned before field IDs.
                _meta = new PortableMetadataImpl(_typeId, _typeName, newFields, _affKeyFieldName);
                _ids = newIds;
            }
        }