private void AddRecordFields( IEnumerable <MemberSerializationInfo> members, Dictionary <string, NamedSchema> schemas, uint currentDepth, RecordSchema record) { int index = 0; foreach (MemberSerializationInfo info in members) { var property = info.MemberInfo as PropertyInfo; var field = info.MemberInfo as FieldInfo; Type memberType; if (property != null) { memberType = property.PropertyType; } else if (field != null) { memberType = field.FieldType; } else { throw new SerializationException( string.Format( CultureInfo.InvariantCulture, "Type member '{0}' is not supported.", info.MemberInfo.GetType().Name)); } TypeSchema fieldSchema = this.TryBuildUnionSchema(memberType, info.MemberInfo, schemas, currentDepth) ?? this.TryBuildFixedSchema(memberType, info.MemberInfo, record) ?? this.CreateSchema(info.Nullable, memberType, schemas, currentDepth + 1, info.DefaultValue?.GetType()); var aliases = info .Aliases .ToList(); var recordField = new RecordField( new NamedEntityAttributes(new SchemaName(info.Name), aliases, info.Doc), fieldSchema, SortOrder.Ascending, info.HasDefaultValue, info.DefaultValue, info.MemberInfo, index++); record.AddField(recordField); } }
/// <summary> /// Sets the fields. /// </summary> /// <param name="record"> /// The record. /// </param> /// <param name="fields"> /// The fields. /// </param> internal static void SetFields(RecordSchema record, IEnumerable <RecordField> fields) { if (record == null) { throw new ArgumentNullException("record"); } if (fields == null) { throw new ArgumentNullException("fields"); } if (record.Fields.Count != 0) { throw new InvalidOperationException("Fields can be set only on empty record."); } int fieldPosition = 0; foreach (var field in fields) { record.AddField(new RecordField(field.NamedEntityAttributes, field.TypeSchema, field.Order, field.HasDefaultValue, field.DefaultValue, field.MemberInfo, fieldPosition++)); } }