Example #1
0
        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.MemberType));
                }

                TypeSchema fieldSchema = this.TryBuildUnionSchema(memberType, info.MemberInfo, schemas, currentDepth)
                                         ?? this.TryBuildFixedSchema(memberType, info.MemberInfo, record)
                                         ?? this.CreateSchema(info.Nullable, memberType, schemas, currentDepth + 1);

                var aliases = info
                              .Aliases
                              .Select(alias => alias.Contains(".") ? alias : record.Namespace + "." + alias)
                              .ToList();
                var recordField = new RecordField(
                    new NamedEntityAttributes(new SchemaName(info.Name), aliases, info.Doc),
                    fieldSchema,
                    SortOrder.Ascending,
                    false,
                    null,
                    info.MemberInfo,
                    index++);
                record.AddField(recordField);
            }
        }
        /// <summary>
        /// Sets the fields.
        /// </summary>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <param name="fields">
        /// The fields.
        /// </param>
        public 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++));
            }
        }
        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.MemberType));
                }

                TypeSchema fieldSchema = this.TryBuildUnionSchema(memberType, info.MemberInfo, schemas, currentDepth)
                                         ?? this.TryBuildFixedSchema(memberType, info.MemberInfo, record)
                                         ?? this.CreateSchema(info.Nullable, memberType, schemas, currentDepth + 1);

                var aliases = info
                    .Aliases
                    .Select(alias => alias.Contains(".") ? alias : record.Namespace + "." + alias)
                    .ToList();
                var recordField = new RecordField(
                    new NamedEntityAttributes(new SchemaName(info.Name), aliases, info.Doc),
                    fieldSchema,
                    SortOrder.Ascending,
                    false,
                    null,
                    info.MemberInfo,
                    index++);
                record.AddField(recordField);
            }
        }
Example #4
0
        /// <summary>
        /// Sets the fields.
        /// </summary>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <param name="fields">
        /// The fields.
        /// </param>
        public 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++));
            }
        }