VerifyType() private static method

Verifies that the given object is of the correct type to be a valid value for the given field.
For repeated fields, this checks if the object is of the right element type, not whether it's a list.
The value is not of the right type. The value is null.
private static VerifyType ( FieldDescriptor field, object value ) : void
field FieldDescriptor
value object
return void
示例#1
0
 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;
     }
 }
示例#2
0
        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);
        }
示例#3
0
 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;
     }
 }