https://github.com/jp2masa/avalonia.propertygenerator
Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.
https://github.com/jp2masa/avalonia.propertygenerator
attached avalonia csharp direct dotnet dotnet-core generator property roslyn source styled
Last synced: 6 months ago
JSON representation
Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.
- Host: GitHub
- URL: https://github.com/jp2masa/avalonia.propertygenerator
- Owner: jp2masa
- License: mit
- Created: 2021-01-28T02:24:29.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-01T19:30:33.000Z (over 2 years ago)
- Last Synced: 2025-04-04T01:23:29.336Z (7 months ago)
- Topics: attached, avalonia, csharp, direct, dotnet, dotnet-core, generator, property, roslyn, source, styled
- Language: C#
- Homepage:
- Size: 64.5 KB
- Stars: 23
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://ci.appveyor.com/project/jp2masa/avalonia-propertygenerator/branch/master)
[](https://www.nuget.org/packages/jp2masa.Avalonia.PropertyGenerator.CSharp/)
[](https://www.myget.org/feed/jp2masa/package/nuget/jp2masa.Avalonia.PropertyGenerator.CSharp)# Avalonia.PropertyGenerator
Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.
## Usage
1. Add reference to `jp2masa.Avalonia.PropertyGenerator.CSharp` package:
```xml
```
2. Declare Avalonia properties as usual, except the CLR members, which are now automatically generated!
## Example
### Source
```cs
using Avalonia.Controls;
using Avalonia.Controls.Primitives;namespace Avalonia.PropertyGenerator.CSharp.Demo
{
internal sealed partial class DemoControl : TemplatedControl
{
public static readonly StyledProperty NumberProperty =
AvaloniaProperty.Register(nameof(Number));[BackingField(Name = "m_text", Accessibility = BackingFieldAccessibility.Internal)]
public static readonly DirectProperty TextProperty =
AvaloniaProperty.RegisterDirect(nameof(Text), o => o.Text, (o, v) => o.Text = v);public static readonly AttachedProperty BoolProperty =
AvaloniaProperty.RegisterAttached("Bool");public DemoControl()
{
m_text = "Hello World!";
}
}
}
```### Generated code
```cs
namespace Avalonia.PropertyGenerator.CSharp.Demo
{
partial class DemoControl
{
public double Number
{
get => GetValue(NumberProperty);
set => SetValue(NumberProperty, value);
}internal string? m_text;
public string? Text
{
get => m_text;
set => SetAndRaise(TextProperty, ref m_text, value);
}public static bool GetBool(Avalonia.AvaloniaObject obj) => obj.GetValue(BoolProperty);
public static void SetBool(Avalonia.AvaloniaObject obj, bool value) => obj.SetValue(BoolProperty, value);
}
}```
## TODO
- Readonly direct properties
- Generate XML documentation