/// <summary>
        /// Clears an extension.
        /// </summary>
        public TBuilder ClearExtension <TExtension>(GeneratedExtensionBase <TExtension> extension)
        {
            ExtendableMessage <TMessage, TBuilder> message = MessageBeingBuilt;

            message.VerifyExtensionContainingType(extension);
            message.Extensions.ClearField(extension.Descriptor);
            return(ThisBuilder);
        }
        /// <summary>
        /// Sets the value of an extension.
        /// </summary>
        public TBuilder SetExtension <TExtension>(GeneratedExtensionBase <TExtension> extension, TExtension value)
        {
            ExtendableMessage <TMessage, TBuilder> message = MessageBeingBuilt;

            message.VerifyExtensionContainingType(extension);
            message.Extensions[extension.Descriptor] = extension.ToReflectionType(value);
            return(ThisBuilder);
        }
        /// <summary>
        /// Appends a value to a repeated extension.
        /// </summary>
        public TBuilder AddExtension <TExtension>(GeneratedExtensionBase <IList <TExtension> > extension, TExtension value)
        {
            ExtendableMessage <TMessage, TBuilder> message = MessageBeingBuilt;

            message.VerifyExtensionContainingType(extension);
            message.Extensions.AddRepeatedField(extension.Descriptor, extension.SingularToReflectionType(value));
            return(ThisBuilder);
        }
 internal void VerifyExtensionContainingType <TExtension>(GeneratedExtensionBase <TExtension> extension)
 {
     if (extension.Descriptor.ContainingType != DescriptorForType)
     {
         // This can only happen if someone uses unchecked operations.
         throw new ArgumentException("Extension is for type \"" + extension.Descriptor.ContainingType.FullName
                                     + "\" which does not match message type \"" + DescriptorForType.FullName + "\".");
     }
 }
 /// <summary>
 /// Add an extension from a generated file to the registry.
 /// </summary>
 public void Add <TExtension> (GeneratedExtensionBase <TExtension> extension)
 {
     if (extension.Descriptor.MappedType == MappedType.Message)
     {
         Add(new ExtensionInfo(extension.Descriptor, extension.MessageDefaultInstance));
     }
     else
     {
         Add(new ExtensionInfo(extension.Descriptor, null));
     }
 }
        /// <summary>
        /// Returns the value of an extension.
        /// </summary>
        public TExtension GetExtension <TExtension>(GeneratedExtensionBase <TExtension> extension)
        {
            object value = extensions[extension.Descriptor];

            if (value == null)
            {
                return((TExtension)extension.MessageDefaultInstance);
            }
            else
            {
                return((TExtension)extension.FromReflectionType(value));
            }
        }
 /// <summary>
 /// Returns one element of a repeated extension.
 /// </summary>
 public TExtension GetExtension <TExtension>(GeneratedExtensionBase <IList <TExtension> > extension, int index)
 {
     return((TExtension)extension.SingularFromReflectionType(extensions[extension.Descriptor, index]));
 }
 /// <summary>
 /// Returns the number of elements in a repeated extension.
 /// </summary>
 public int GetExtensionCount <TExtension>(GeneratedExtensionBase <IList <TExtension> > extension)
 {
     return(extensions.GetRepeatedFieldCount(extension.Descriptor));
 }
 /// <summary>
 /// Checks if a singular extension is present.
 /// </summary>
 public bool HasExtension <TExtension>(GeneratedExtensionBase <TExtension> extension)
 {
     return(extensions.HasField(extension.Descriptor));
 }
 /// <summary>
 /// Returns one element of a repeated extension.
 /// </summary>
 public TExtension GetExtension <TExtension>(GeneratedExtensionBase <IList <TExtension> > extension, int index)
 {
     return(MessageBeingBuilt.GetExtension(extension, index));
 }
 /// <summary>
 /// Returns the value of an extension.
 /// </summary>
 public TExtension GetExtension <TExtension>(GeneratedExtensionBase <TExtension> extension)
 {
     return(MessageBeingBuilt.GetExtension(extension));
 }
 /// <summary>
 /// Returns the number of elements in a repeated extension.
 /// </summary>
 public int GetExtensionCount <TExtension>(GeneratedExtensionBase <IList <TExtension> > extension)
 {
     return(MessageBeingBuilt.GetExtensionCount(extension));
 }
 /// <summary>
 /// Checks if a singular extension is present
 /// </summary>
 public bool HasExtension <TExtension>(GeneratedExtensionBase <TExtension> extension)
 {
     return(MessageBeingBuilt.HasExtension(extension));
 }