using System; using System.Reflection; namespace Google.Protobuf.Reflection { // Token: 0x0200005C RID: 92 public sealed class FieldDescriptor : DescriptorBase, IComparable { // Token: 0x17000172 RID: 370 // (get) Token: 0x06000587 RID: 1415 RVA: 0x00013B9A File Offset: 0x00011D9A public MessageDescriptor ContainingType { get; } // Token: 0x17000173 RID: 371 // (get) Token: 0x06000588 RID: 1416 RVA: 0x00013BA2 File Offset: 0x00011DA2 public OneofDescriptor ContainingOneof { get; } // Token: 0x17000174 RID: 372 // (get) Token: 0x06000589 RID: 1417 RVA: 0x00013BAA File Offset: 0x00011DAA public string JsonName { get; } // Token: 0x17000175 RID: 373 // (get) Token: 0x0600058A RID: 1418 RVA: 0x00013BB2 File Offset: 0x00011DB2 internal FieldDescriptorProto Proto { get; } // Token: 0x0600058B RID: 1419 RVA: 0x00013BBC File Offset: 0x00011DBC internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string propertyName) : base(file, file.ComputeFullName(parent, proto.Name), index) { this.Proto = proto; if (proto.Type != (FieldDescriptorProto.Types.Type)0) { this.fieldType = FieldDescriptor.GetFieldTypeFromProtoType(proto.Type); } if (this.FieldNumber <= 0) { throw new DescriptorValidationException(this, "Field numbers must be positive integers."); } this.ContainingType = parent; if (proto.OneofIndex != -1) { if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count) { throw new DescriptorValidationException(this, string.Format("FieldDescriptorProto.oneof_index is out of range for type {0}", parent.Name)); } this.ContainingOneof = parent.Oneofs[proto.OneofIndex]; } file.DescriptorPool.AddSymbol(this); this.propertyName = propertyName; this.JsonName = ((this.Proto.JsonName == "") ? JsonFormatter.ToCamelCase(this.Proto.Name) : this.Proto.JsonName); } // Token: 0x17000176 RID: 374 // (get) Token: 0x0600058C RID: 1420 RVA: 0x00013CC1 File Offset: 0x00011EC1 public override string Name { get { return this.Proto.Name; } } // Token: 0x17000177 RID: 375 // (get) Token: 0x0600058D RID: 1421 RVA: 0x00013CCE File Offset: 0x00011ECE public IFieldAccessor Accessor { get { return this.accessor; } } // Token: 0x0600058E RID: 1422 RVA: 0x00013CD8 File Offset: 0x00011ED8 private static FieldType GetFieldTypeFromProtoType(FieldDescriptorProto.Types.Type type) { switch (type) { case FieldDescriptorProto.Types.Type.Double: return FieldType.Double; case FieldDescriptorProto.Types.Type.Float: return FieldType.Float; case FieldDescriptorProto.Types.Type.Int64: return FieldType.Int64; case FieldDescriptorProto.Types.Type.Uint64: return FieldType.UInt64; case FieldDescriptorProto.Types.Type.Int32: return FieldType.Int32; case FieldDescriptorProto.Types.Type.Fixed64: return FieldType.Fixed64; case FieldDescriptorProto.Types.Type.Fixed32: return FieldType.Fixed32; case FieldDescriptorProto.Types.Type.Bool: return FieldType.Bool; case FieldDescriptorProto.Types.Type.String: return FieldType.String; case FieldDescriptorProto.Types.Type.Group: return FieldType.Group; case FieldDescriptorProto.Types.Type.Message: return FieldType.Message; case FieldDescriptorProto.Types.Type.Bytes: return FieldType.Bytes; case FieldDescriptorProto.Types.Type.Uint32: return FieldType.UInt32; case FieldDescriptorProto.Types.Type.Enum: return FieldType.Enum; case FieldDescriptorProto.Types.Type.Sfixed32: return FieldType.SFixed32; case FieldDescriptorProto.Types.Type.Sfixed64: return FieldType.SFixed64; case FieldDescriptorProto.Types.Type.Sint32: return FieldType.SInt32; case FieldDescriptorProto.Types.Type.Sint64: return FieldType.SInt64; default: throw new ArgumentException("Invalid type specified"); } } // Token: 0x17000178 RID: 376 // (get) Token: 0x0600058F RID: 1423 RVA: 0x00013D6E File Offset: 0x00011F6E public bool IsRepeated { get { return this.Proto.Label == FieldDescriptorProto.Types.Label.Repeated; } } // Token: 0x17000179 RID: 377 // (get) Token: 0x06000590 RID: 1424 RVA: 0x00013D7E File Offset: 0x00011F7E public bool IsMap { get { return this.fieldType == FieldType.Message && this.messageType.Proto.Options != null && this.messageType.Proto.Options.MapEntry; } } // Token: 0x1700017A RID: 378 // (get) Token: 0x06000591 RID: 1425 RVA: 0x00013DB3 File Offset: 0x00011FB3 public bool IsPacked { get { return this.Proto.Options == null || this.Proto.Options.Packed; } } // Token: 0x1700017B RID: 379 // (get) Token: 0x06000592 RID: 1426 RVA: 0x00013DD4 File Offset: 0x00011FD4 public FieldType FieldType { get { return this.fieldType; } } // Token: 0x1700017C RID: 380 // (get) Token: 0x06000593 RID: 1427 RVA: 0x00013DDC File Offset: 0x00011FDC public int FieldNumber { get { return this.Proto.Number; } } // Token: 0x06000594 RID: 1428 RVA: 0x00013DE9 File Offset: 0x00011FE9 public int CompareTo(FieldDescriptor other) { if (other.ContainingType != this.ContainingType) { throw new ArgumentException("FieldDescriptors can only be compared to other FieldDescriptors for fields of the same message type."); } return this.FieldNumber - other.FieldNumber; } // Token: 0x1700017D RID: 381 // (get) Token: 0x06000595 RID: 1429 RVA: 0x00013E11 File Offset: 0x00012011 public EnumDescriptor EnumType { get { if (this.fieldType != FieldType.Enum) { throw new InvalidOperationException("EnumType is only valid for enum fields."); } return this.enumType; } } // Token: 0x1700017E RID: 382 // (get) Token: 0x06000596 RID: 1430 RVA: 0x00013E2E File Offset: 0x0001202E public MessageDescriptor MessageType { get { if (this.fieldType != FieldType.Message) { throw new InvalidOperationException("MessageType is only valid for message fields."); } return this.messageType; } } // Token: 0x06000597 RID: 1431 RVA: 0x00013E4C File Offset: 0x0001204C internal void CrossLink() { if (this.Proto.TypeName != "") { IDescriptor descriptor = base.File.DescriptorPool.LookupSymbol(this.Proto.TypeName, this); if (this.Proto.Type != (FieldDescriptorProto.Types.Type)0) { if (descriptor is MessageDescriptor) { this.fieldType = FieldType.Message; } else { if (!(descriptor is EnumDescriptor)) { throw new DescriptorValidationException(this, string.Format("\"{0}\" is not a type.", this.Proto.TypeName)); } this.fieldType = FieldType.Enum; } } if (this.fieldType == FieldType.Message) { if (!(descriptor is MessageDescriptor)) { throw new DescriptorValidationException(this, string.Format("\"{0}\" is not a message type.", this.Proto.TypeName)); } this.messageType = (MessageDescriptor)descriptor; if (this.Proto.DefaultValue != "") { throw new DescriptorValidationException(this, "Messages can't have default values."); } } else { if (this.fieldType != FieldType.Enum) { throw new DescriptorValidationException(this, "Field with primitive type has type_name."); } if (!(descriptor is EnumDescriptor)) { throw new DescriptorValidationException(this, string.Format("\"{0}\" is not an enum type.", this.Proto.TypeName)); } this.enumType = (EnumDescriptor)descriptor; } } else if (this.fieldType == FieldType.Message || this.fieldType == FieldType.Enum) { throw new DescriptorValidationException(this, "Field with message or enum type missing type_name."); } base.File.DescriptorPool.AddFieldByNumber(this); if (this.ContainingType != null && this.ContainingType.Proto.Options != null && this.ContainingType.Proto.Options.MessageSetWireFormat) { throw new DescriptorValidationException(this, "MessageSet format is not supported."); } this.accessor = this.CreateAccessor(); } // Token: 0x06000598 RID: 1432 RVA: 0x00013FFC File Offset: 0x000121FC private IFieldAccessor CreateAccessor() { if (this.propertyName == null) { return null; } PropertyInfo property = this.ContainingType.ClrType.GetProperty(this.propertyName); if (property == null) { throw new DescriptorValidationException(this, string.Format("Property {0} not found in {1}", this.propertyName, this.ContainingType.ClrType)); } if (this.IsMap) { return new MapFieldAccessor(property, this); } if (!this.IsRepeated) { return new SingleFieldAccessor(property, this); } return new RepeatedFieldAccessor(property, this); } // Token: 0x04000218 RID: 536 private EnumDescriptor enumType; // Token: 0x04000219 RID: 537 private MessageDescriptor messageType; // Token: 0x0400021A RID: 538 private FieldType fieldType; // Token: 0x0400021B RID: 539 private readonly string propertyName; // Token: 0x0400021C RID: 540 private IFieldAccessor accessor; } }