Giter Site home page Giter Site logo

jp2masa / avalonia.propertygenerator Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 0.0 66 KB

Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.

License: MIT License

C# 100.00%
avalonia property styled direct attached roslyn source generator dotnet dotnet-core csharp

avalonia.propertygenerator's Introduction

Build status NuGet MyGet

Avalonia.PropertyGenerator

Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.

Usage

  1. Add reference to jp2masa.Avalonia.PropertyGenerator.CSharp package:
<PackageReference Include="jp2masa.Avalonia.PropertyGenerator.CSharp" Version="0.10.0-beta2" PrivateAssets="All" />
  1. Declare Avalonia properties as usual, except the CLR members, which are now automatically generated!

Example

Source

using Avalonia.Controls;
using Avalonia.Controls.Primitives;

namespace Avalonia.PropertyGenerator.CSharp.Demo
{
    internal sealed partial class DemoControl : TemplatedControl
    {
        public static readonly StyledProperty<double> NumberProperty =
            AvaloniaProperty.Register<DemoControl, double>(nameof(Number));

        [BackingField(Name = "m_text", Accessibility = BackingFieldAccessibility.Internal)]
        public static readonly DirectProperty<DemoControl, string?> TextProperty =
            AvaloniaProperty.RegisterDirect<DemoControl, string?>(nameof(Text), o => o.Text, (o, v) => o.Text = v);

        public static readonly AttachedProperty<bool> BoolProperty =
            AvaloniaProperty.RegisterAttached<DemoControl, Control, bool>("Bool");

        public DemoControl()
        {
            m_text = "Hello World!";
        }
    }
}

Generated code

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

avalonia.propertygenerator's People

Contributors

jp2masa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.