/// <summary> /// Constructor /// </summary> /// <param name="t">type of the class</param> /// <param name="r">record schema</param> /// <param name="cache">class cache - can be reused</param> public DotnetClass(Type t, RecordSchema r, ClassCache cache) { _type = t; foreach (var f in r.Fields) { bool hasAttribute = false; PropertyInfo prop = GetPropertyInfo(f); foreach (var attr in prop.GetCustomAttributes(true)) { var avroAttr = attr as AvroFieldAttribute; if (avroAttr != null) { hasAttribute = true; _propertyMap.TryAdd(f.Name, new DotnetProperty(prop, f.Schema.Tag, avroAttr.Converter, cache)); break; } } if (!hasAttribute) { _propertyMap.TryAdd(f.Name, new DotnetProperty(prop, f.Schema.Tag, cache)); } } }
public DotnetProperty(PropertyInfo property, Avro.Schema.Type schemaTag, IAvroFieldConverter converter, ClassCache cache) { _property = property; Converter = converter; if (!IsPropertyCompatible(schemaTag)) { if (Converter == null) { var c = cache.GetDefaultConverter(schemaTag, _property.PropertyType); if (c != null) { Converter = c; return; } } throw new AvroException($"Property {property.Name} in object {property.DeclaringType} isn't compatible with Avro schema type {schemaTag}"); } }
public DotnetProperty(PropertyInfo property, Avro.Schema.Type schemaTag, ClassCache cache) : this(property, schemaTag, null, cache) { }