Kafka.Autofill 0.9.6

Suggested Alternatives

Avro.Autofill

Additional Details

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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kafka.Autofill" Version="0.9.6">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kafka.Autofill" Version="0.9.6" />
                    
Directory.Packages.props
<PackageReference Include="Kafka.Autofill">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kafka.Autofill --version 0.9.6
                    
#r "nuget: Kafka.Autofill, 0.9.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kafka.Autofill@0.9.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kafka.Autofill&version=0.9.6
                    
Install as a Cake Addin
#tool nuget:?package=Kafka.Autofill&version=0.9.6
                    
Install as a Cake Tool

Kafka.Autofill

NuGet

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, string
  • uint (serialized as long)
  • ulong (serialized as bytes)
  • decimal (serialized as double)
  • byte[]
  • Guid (uuid)

Date/Time

  • DateTime (timestamp-millis)
  • DateTimeOffset (timestamp-millis)
  • DateOnly (timestamp-millis)

Collections

  • T[] - Arrays
  • List<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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last Updated
0.9.6 187 2/17/2026 0.9.6 is deprecated because it is no longer maintained.
0.9.4 114 2/16/2026
0.9.3 124 2/15/2026
0.9.0 117 2/15/2026
0.7.2 110 2/15/2026
0.7.1 110 2/15/2026
0.6.0 114 2/15/2026
0.5.0 118 2/15/2026