internal object this[IFieldDescriptorLite field, int index] { get { if (!field.IsRepeated) { throw new ArgumentException("Indexer specifying field and index can only be called on repeated fields."); } return(((IList <object>) this[field])[index]); } set { if (!field.IsRepeated) { throw new ArgumentException("Indexer specifying field and index can only be called on repeated fields."); } FieldSet.VerifyType(field, value); object obj; if (!this.fields.TryGetValue(field, out obj)) { throw new ArgumentOutOfRangeException(); } ((IList <object>)obj)[index] = value; } }
internal void AddRepeatedField(IFieldDescriptorLite field, object value) { if (!field.IsRepeated) { throw new ArgumentException("AddRepeatedField can only be called on repeated fields."); } FieldSet.VerifyType(field, value); object obj; if (!this.fields.TryGetValue(field, out obj)) { obj = new List <object>(); this.fields[field] = obj; } ((IList <object>)obj).Add(value); }
internal object this[IFieldDescriptorLite field] { get { object result; if (this.fields.TryGetValue(field, out result)) { return(result); } if (field.MappedType != MappedType.Message) { return(field.DefaultValue); } if (field.IsRepeated) { return(new List <object>()); } return(null); } set { if (field.IsRepeated) { List <object> list = value as List <object>; if (list == null) { throw new ArgumentException("Wrong object type used with protocol message reflection."); } List <object> list2 = new List <object>(list); using (List <object> .Enumerator enumerator = list2.GetEnumerator()) { while (enumerator.MoveNext()) { object current = enumerator.Current; FieldSet.VerifyType(field, current); } } value = list2; } else { FieldSet.VerifyType(field, value); } this.fields[field] = value; } }