Exemple #1
0
        /// <summary>
        /// Makes this FieldSet immutable, and returns it for convenience. Any
        /// mutable repeated fields are made immutable, as well as the map itself.
        /// </summary>
        internal FieldSet MakeImmutable()
        {
            // First check if we have any repeated values
            bool hasRepeats = false;

            foreach (object value in fields.Values)
            {
                IList <object> list = value as IList <object>;
                if (list != null && !list.IsReadOnly)
                {
                    hasRepeats = true;
                    break;
                }
            }

            if (hasRepeats)
            {
                var tmp = new SortedList <IFieldDescriptorLite, object>();
                foreach (KeyValuePair <IFieldDescriptorLite, object> entry in fields)
                {
                    IList <object> list = entry.Value as IList <object>;
                    tmp[entry.Key] = list == null ? entry.Value : Lists.AsReadOnly(list);
                }
                fields = tmp;
            }

            fields = Dictionaries.AsReadOnly(fields);

            return(this);
        }
Exemple #2
0
        internal FieldSet MakeImmutable()
        {
            bool flag = false;

            using (IEnumerator <object> enumerator = this.fields.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    object         current = enumerator.Current;
                    IList <object> list    = current as IList <object>;
                    if (list != null && !list.IsReadOnly)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (flag)
            {
                SortedList <IFieldDescriptorLite, object> sortedList = new SortedList <IFieldDescriptorLite, object>();
                using (IEnumerator <KeyValuePair <IFieldDescriptorLite, object> > enumerator2 = this.fields.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        KeyValuePair <IFieldDescriptorLite, object> current2 = enumerator2.Current;
                        IList <object> list2 = current2.Value as IList <object>;
                        sortedList[current2.Key] = ((list2 == null) ? current2.Value : Lists.AsReadOnly <object>(list2));
                    }
                }
                this.fields = sortedList;
            }
            this.fields = Dictionaries.AsReadOnly <IFieldDescriptorLite, object>(this.fields);
            return(this);
        }
Exemple #3
0
        private static IDictionary <FieldType, MappedType> MapFieldTypes()
        {
            var map = new Dictionary <FieldType, MappedType>();

            foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                FieldType             fieldType = (FieldType)field.GetValue(null);
                FieldMappingAttribute mapping   = (FieldMappingAttribute)field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
                map[fieldType] = mapping.MappedType;
            }
            return(Dictionaries.AsReadOnly(map));
        }
Exemple #4
0
        private static IDictionary <FieldType, FieldMappingAttribute> MapFieldTypes()
        {
            Dictionary <FieldType, FieldMappingAttribute> dictionary = new Dictionary <FieldType, FieldMappingAttribute>();

            FieldInfo[] fields = typeof(FieldType).GetFields((BindingFlags)24);
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo             fieldInfo             = fields[i];
                FieldType             fieldType             = (FieldType)fieldInfo.GetValue(null);
                FieldMappingAttribute fieldMappingAttribute = (FieldMappingAttribute)fieldInfo.GetCustomAttributes(typeof(FieldMappingAttribute), false).GetEnumerator().Current;
                dictionary[fieldType] = fieldMappingAttribute;
            }
            return(Dictionaries.AsReadOnly <FieldType, FieldMappingAttribute>(dictionary));
        }