Example #1
0
        /// <summary>
        /// Adds an enum value to the enumValuesByNumber table. If an enum value
        /// with the same type and number already exists, this method does nothing.
        /// (This is allowed; the first value defined with the number takes precedence.)
        /// </summary>
        public void AddEnumValueByNumber(EnumValueDescriptor enumValue)
        {
            DescriptorIntPair key = new DescriptorIntPair(enumValue.EnumDescriptor, enumValue.Number);

            if (!enumValuesByNumber.ContainsKey(key))
            {
                enumValuesByNumber[key] = enumValue;
            }
        }
Example #2
0
        /// <summary>
        /// Adds a field to the fieldsByNumber table.
        /// </summary>
        /// <exception cref="DescriptorValidationException">A field with the same
        /// containing type and number already exists.</exception>
        internal void AddFieldByNumber(FieldDescriptor field)
        {
            DescriptorIntPair key = new DescriptorIntPair(field.ContainingType, field.FieldNumber);

            if (fieldsByNumber.TryGetValue(key, out FieldDescriptor old))
            {
                throw new DescriptorValidationException(field, "Field number " + field.FieldNumber +
                                                        "has already been used in \"" +
                                                        field.ContainingType.FullName +
                                                        "\" by field \"" + old.Name + "\".");
            }
            fieldsByNumber[key] = field;
        }