Пример #1
0
        private NamedEntityAttributes GetNamedEntityAttributesFrom(Type type)
        {
            AvroContractResolver  resolver = this.settings.Resolver;
            TypeSerializationInfo typeInfo = resolver.ResolveType(type);
            var name    = new SchemaName(typeInfo.Name, typeInfo.Namespace);
            var aliases = typeInfo
                          .Aliases
                          .Select(alias => string.IsNullOrEmpty(name.Namespace) || alias.Contains(".") ? alias : name.Namespace + "." + alias)
                          .ToList();

            return(new NamedEntityAttributes(name, aliases, typeInfo.Doc));
        }
Пример #2
0
        /// <summary>
        /// Generates the record type schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="schemas">The schemas.</param>
        /// <param name="currentDepth">The current depth.</param>
        /// <returns>
        /// Instance of schema.
        /// </returns>
        private TypeSchema BuildRecordTypeSchema(Type type, Dictionary <string, NamedSchema> schemas, uint currentDepth)
        {
            if (schemas.TryGetValue(type.ToString(), out var schema))
            {
                return(schema);
            }

            var attr = GetNamedEntityAttributesFrom(type);
            AvroContractResolver resolver = this.settings.Resolver;
            var record = new RecordSchema(
                attr,
                type);

            schemas.Add(type.ToString(), record);

            var members = resolver.ResolveMembers(type);

            this.AddRecordFields(members, schemas, currentDepth, record);
            return(record);
        }