/// <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> internal void AddEnumValueByNumber(EnumValueDescriptor enumValue) { ObjectIntPair <IDescriptor> key = new ObjectIntPair <IDescriptor>(enumValue.EnumDescriptor, enumValue.Number); if (!enumValuesByNumber.ContainsKey(key)) { enumValuesByNumber[key] = enumValue; } }
/// <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) { // for extensions, we use the extended type, otherwise we use the containing type ObjectIntPair <IDescriptor> key = new ObjectIntPair <IDescriptor>(field.Proto.HasExtendee ? field.ExtendeeType : 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; }