Пример #1
0
 /// <summary>
 /// Resets the builder to an empty set.
 /// </summary>
 public Builder Clear()
 {
     fields.Clear();
     lastFieldNumber = 0;
     lastField       = null;
     return(this);
 }
Пример #2
0
            /// <summary>
            /// Returns a field builder for the specified field number, including any values
            /// which already exist.
            /// </summary>
            private UnknownField.Builder GetFieldBuilder(int number)
            {
                if (lastField != null)
                {
                    if (number == lastFieldNumber)
                    {
                        return(lastField);
                    }
                    // Note: AddField() will reset lastField and lastFieldNumber.
                    AddField(lastFieldNumber, lastField.Build());
                }
                if (number == 0)
                {
                    return(null);
                }

                lastField = UnknownField.CreateBuilder();
                UnknownField existing;

                if (fields.TryGetValue(number, out existing))
                {
                    lastField.MergeFrom(existing);
                }
                lastFieldNumber = number;
                return(lastField);
            }
Пример #3
0
 /// <summary>
 /// Adds a field to the set. If a field with the same number already exists, it
 /// is replaced.
 /// </summary>
 public Builder AddField(int number, UnknownField field)
 {
     if (number == 0)
     {
         throw new ArgumentOutOfRangeException("number", "Zero is not a valid field number.");
     }
     if (lastField != null && lastFieldNumber == number)
     {
         // Discard this.
         lastField       = null;
         lastFieldNumber = 0;
     }
     fields[number] = field;
     return(this);
 }