AvaSourceGenerators 0.1.1
See the version list below for details.
dotnet add package AvaSourceGenerators --version 0.1.1
NuGet\Install-Package AvaSourceGenerators -Version 0.1.1
<PackageReference Include="AvaSourceGenerators" Version="0.1.1" />
paket add AvaSourceGenerators --version 0.1.1
#r "nuget: AvaSourceGenerators, 0.1.1"
// Install AvaSourceGenerators as a Cake Addin
#addin nuget:?package=AvaSourceGenerators&version=0.1.1
// Install AvaSourceGenerators as a Cake Tool
#tool nuget:?package=AvaSourceGenerators&version=0.1.1
AvaSourceGenerators
Source generators for AvaloniaUI boilerplate code.
Example
At the moment only the StyledProperty generator is implemented. To use it, simply declare a class as partial and annotate a field with the AvaStyledProperty attribute:
using Avalonia.Controls.Primitives;
using Lucdem.Avalonia.SourceGenerators.Attributes;
namespace Lucdem.Avalonia.SourceGenerators.Sample.Controls;
public partial class LabeledButton : TemplatedControl
{
public LabeledButton() { }
[AvaStyledProperty]
private string labelText = string.Empty;
}
The source generator will detect the attribute annotated field and create another partial class declaration with the basic StyledProperty boilerplate:
public static readonly StyledProperty<string> LabelTextProperty = AvaloniaProperty.Register<LabeledButton, string>("LabelText");
public string LabelText
{
get => GetValue(LabelTextProperty);
set => SetValue(LabelTextProperty, value);
}
Well, or something equivalent to that at least. The exact output of the code generator is not exactly made for human eyes:
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace Lucdem.Avalonia.SourceGenerators.Sample.Controls
{
/// <inheritdoc/>
partial class LabeledButton
{
public static readonly global::Avalonia.StyledProperty<string> LabelTextProperty = global::Avalonia.AvaloniaProperty.Register<LabeledButton, string>("LabelText");
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.CodeDom.Compiler.GeneratedCode("Lucdem.Avalonia.SourceGenerators.Generators.StyledPropertyGenerator", "0.1.0.0")]
public string LabelText { get => GetValue(LabelTextProperty); set => SetValue(LabelTextProperty, value); }
}
}
How to use
The project is available as a nuget package under the name of AvaSourceGenerators. To use it simply add to the csproj file:
<ItemGroup>
<PackageReference Include="AvaSourceGenerators" Version="0.1.0.11"/>
</ItemGroup>
How to inspect generated source code in VisualStudio
After including the project, in the solution explorer, go to {YourProject}->Dependencies->Analyzers->Lucdem.Avalonia.SourceGenerators->{NameOfTheGenerator}.
TODO list
- Add Diagnostics (warn user that the class should inherit from AvaloniaObject, that the annotated field must start with lower case character, etc)
- Add generators for attached and direct properties
- Maybe use field value as the default value for the property?
- Add a way to mark a function as the validation function for a property (something like a [AvaPropValidator(nameof(PropertyName))] annotation maybe?)
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. |
.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. |
-
.NETStandard 2.0
- 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.