Avroify 1.2.0

dotnet add package Avroify --version 1.2.0
NuGet\Install-Package Avroify -Version 1.2.0
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="Avroify" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Avroify --version 1.2.0
#r "nuget: Avroify, 1.2.0"
#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.
// Install Avroify as a Cake Addin
#addin nuget:?package=Avroify&version=1.2.0

// Install Avroify as a Cake Tool
#tool nuget:?package=Avroify&version=1.2.0

Avroify

Build Build

Source Generator that allows you to extend your data models to be used for Avro Serialization and Deserialization.

Removes the need to run external steps during your development process to add Avro support or even generate classes from a given Schema.

Currently supports extending existing classes as well as generating classes for .avcs schema files.

[toc]

Usage

Install the Avroify Package

dotnet add package Avroify 

Once installed you can either use avcs schema files or annotating classes for avrofication.

NOTE: Application will need to reference Apache.Avro

Features

  • Simplifies creation of Schemas for your classes
  • Generate usable classes from avcs files
  • Respects Nullable Annotation settings
  • Override namings to help with refactorings

.Net to Avro Mappings

.NET Type Avro Type
Boolean Boolean
Char Int
String String
Byte Int
Short Int
Int Int
Long Long
Single Float
Double Double
Decimal AvroDecimal*
DateTime long (Logical Type: timestamp-millis)
DateOnly int (Logical Type: date)
TimeOnly int (Logical Type: time-millis)
List Array
Array Array
Dictionary Map**
Enum Enum
Class Record

* AvroDecimals are represented as bytes types and logical types of decimal with a precision of 29 and scale of 14

** Maps expect the key to be a string type, currently there is not way to change the key type on the schema

Examples

AVCS Files

Add the file to your project, then right click select properties and set the build action to AdditionalFiles

Below sample Schema will generate 3 files (2 Classes and 1 Enum)

{
  "name": "SampleAvro",
  "namespace": "Avroify.Sample.Models",
  "type": "record",
  "fields": [
    {
      "name": "Id",
      "type": "long"
    },
    {
      "name": "Age",
      "type": "int"
    },
    {
      "name": "FullName",
      "type": [
        "null",
        "string"
      ]
    },
    {
      "name": "Status",
      "type": {
        "type": "enum",
        "name": "StatusEnum",
        "namespace": "Avroify.Sample.Enums",
        "symbols": [
          "Active",
          "Inactive",
          "Unknown"
        ]
      }
    },
    {
      "name": "Address",
      "type": [
        "null",
        {
          "name": "AddressAvro",
          "namespace": "Avroify.Sample.Models",
          "type": "record",
          "fields": [
            {
              "name": "Street",
              "type": "string"
            },
            {
              "name": "Country",
              "type": [
                "null",
                "string"
              ]
            },
            {
              "name": "PostalCode",
              "type": [
                "null",
                "string"
              ]
            }
          ]
        }
      ]
    }
  ]
}

Attribute Classes

To extend existing classes to support Avro, mark the class as partial and add the [Avroify] attribute to the class.

using System;
using System.Collections.Generic;

namespace Avroify.Sample;

[Avroify]
public partial class AllBaseTypes
{
    public string StringType { get; set; }
    public char CharType { get; set; }
    public byte ByteType { get; set; }
    public short ShortType { get; set; }
    public int IntType { get; set; }
    public long LongType { get; set; }
    public float FloatType { get; set; }
    public double DoubleType { get; set; }
    public decimal DecimalType { get; set; }
    public int[] ArrayType  { get; set; }
    public List<string> ListType { get; set; }
    public Dictionary<string, NestedClass> MapType { get; set; }
    public NestedClass ComplexType { get; set; }
    public DateTime DateTimeType { get; set; }
    public DateOnly DateType { get; set; }
    public TimeOnly TimeType { get; set; }
    public SimpleEnum EnumType { get; set; }
}

[Avroify]
public partial class NestedClass
{
    public string NextStringType { get; set; }
}

public enum SimpleEnum
{
     Active,
     Inactive,
     Deleted
}
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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.

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
1.2.0 60 6/12/2024
1.1.0 114 5/9/2024
1.0.1 95 5/7/2024
1.0.0 59 5/3/2024