Kafka.Autofill
0.9.6
Migrated to netstardard 2.0 to provide wider support for different frameworks
dotnet add package Kafka.Autofill --version 0.9.6
NuGet\Install-Package Kafka.Autofill -Version 0.9.6
<PackageReference Include="Kafka.Autofill" Version="0.9.6"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Kafka.Autofill" Version="0.9.6" />
<PackageReference Include="Kafka.Autofill"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Kafka.Autofill --version 0.9.6
#r "nuget: Kafka.Autofill, 0.9.6"
#:package Kafka.Autofill@0.9.6
#addin nuget:?package=Kafka.Autofill&version=0.9.6
#tool nuget:?package=Kafka.Autofill&version=0.9.6
Kafka.Autofill
A C# source generator and analyzer for Apache Avro serialization in Kafka. Automatically generates Get() and Put() methods and Avro schemas for ISpecificRecord implementations.
Features
Automatic Code Generation - Generates boilerplate serialization code
Live Validation - Real-time errors for unsupported types in the IDE
Schema Generation - Optionally generates Avro schemas at compile time
Type Safety - Compile-time validation of property types
Zero Runtime Dependencies - Only development-time dependency
Quick Start
1. Mark your class with [KafkaAutofill]
using Kafka.Autofill;
using Avro.Specific;
[KafkaAutofill] // Generates Get(), Put(), and Schema
public partial class Person : ISpecificRecord
{
public int Age { get; set; }
public string Name { get; set; } = string.Empty;
public DateTime BirthDate { get; set; }
public List<string> Hobbies { get; set; } = [];
}
2. The source generator creates
public partial class Person
{
private static readonly Schema Cached = Schema.Parse(AvroSchemaGen.GenerateSchema(typeof(Person)));
[AvroIgnore]
public Schema Schema { get; } = Cached;
public object Get(int fieldPos)
{
return fieldPos switch
{
0 => Age,
1 => Name,
2 => BirthDate,
3 => Hobbies,
_ => throw new ArgumentOutOfRangeException(...)
};
}
public void Put(int fieldPos, object fieldValue)
{
switch (fieldPos)
{
case 0: Age = (int)fieldValue; break;
case 1: Name = (string)fieldValue; break;
case 2: BirthDate = (DateTime)fieldValue; break;
case 3: Hobbies = (List<string>)fieldValue; break;
default: throw new ArgumentOutOfRangeException(...);
}
}
}
Supported Types
Primitives
int,long,float,double,bool,stringuint(serialized aslong)ulong(serialized asbytes)decimal(serialized asdouble)byte[]Guid(uuid)
Date/Time
DateTime(timestamp-millis)DateTimeOffset(timestamp-millis)DateOnly(timestamp-millis)
Collections
T[]- ArraysList<T>,HashSet<T>IEnumerable<T>,ICollection<T>,IList<T>Dictionary<string, T>,IDictionary<string, T>(string keys only)
Complex Types
- User-defined classes and structs
- Enums
- Nullable types:
int?,DateTime?,MyEnum?
Nested Types
[KafkaAutofill]
public partial class Person : ISpecificRecord
{
public string Name { get; set; } = string.Empty;
public Address HomeAddress { get; set; } = new();
public List<Address> PreviousAddresses { get; set; } = [];
}
[KafkaAutofill]
public partial class Address : ISpecificRecord
{
public string Street { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
}
Live Type Validation
The analyzer provides real-time errors for unsupported types:
[KafkaAutofill]
public partial class MyClass : ISpecificRecord
{
// ❌ ERROR: Type 'HttpClient' from namespace 'System.Net.Http' is not supported in Avro schema
public HttpClient Client { get; set; }
// ❌ ERROR: Delegate type 'Func' from namespace 'System' is not supported in Avro schema
public Func<string, int> Converter { get; set; }
}
Excluding Properties
Use [AvroIgnore] to exclude properties from serialization:
[KafkaAutofill]
public partial class Person : ISpecificRecord
{
public string Name { get; set; } = string.Empty;
[AvroIgnore]
public Func<string, int> Converter { get; set; } // Won't be serialized
}
Schema Generation Options
Generate schema (default)
[KafkaAutofill] // or [KafkaAutofill(true)]
public partial class Person : ISpecificRecord { }
Skip schema generation
[KafkaAutofill(false)]
public partial class Person : ISpecificRecord { }
Requirements
- .NET Standard 2.1 or later
- C# 9.0 or later (for source generators)
- Apache.Avro NuGet package (for runtime)
Contributing
Contributions are welcome! Please open an issue or pull request on GitHub.
License
MIT License - see LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.