EasyStyledProperty 1.0.3
dotnet add package EasyStyledProperty --version 1.0.3
NuGet\Install-Package EasyStyledProperty -Version 1.0.3
<PackageReference Include="EasyStyledProperty" Version="1.0.3" />
<PackageVersion Include="EasyStyledProperty" Version="1.0.3" />
<PackageReference Include="EasyStyledProperty" />
paket add EasyStyledProperty --version 1.0.3
#r "nuget: EasyStyledProperty, 1.0.3"
#:package EasyStyledProperty@1.0.3
#addin nuget:?package=EasyStyledProperty&version=1.0.3
#tool nuget:?package=EasyStyledProperty&version=1.0.3
EasyStyledProperty# Roslyn Source Generators Sample
用于 Avalonia 的 StyledProperty 源生成器,让您通过简单的特性标注自动生成 StyledProperty 和属性代码。A set of three projects that illustrates Roslyn source generators. Enjoy this template to learn from and modify source generators for your own needs.
安装## Content
SourceGenerators
dotnet add package EasyStyledProperty**You must build this project to see the result (generated code) in the IDE.**
- SampleSourceGenerator.cs: A source generator that creates C# classes based on a text file (in this case, Domain Driven Design ubiquitous language registry).
使用方法- SampleIncrementalSourceGenerator.cs: A source generator that creates a custom report based on class properties. The target class should be annotated with the Generators.ReportAttribute attribute.
1. 在您的 Avalonia 控件类上添加特性### SourceGenerators.Sample
A project that references source generators. Note the parameters of ProjectReference in SourceGenerators.Sample.csproj, they make sure that the project is referenced as a set of source generators.
using EasyStyledProperty;### SourceGenerators.Tests
Unit tests for source generators. The easiest way to develop language-related features is to start with unit tests.
[StyledProperty("Text", typeof(string), "默认文本")]
[StyledProperty("IsEnabled", typeof(bool), true)]## How To?
[StyledProperty("FontSize", typeof(double), 14.0)]### How to debug?
public partial class MyControl : AvaloniaObject- Use the [launchSettings.json](Properties/launchSettings.json) profile.
{- Debug tests.
// 源生成器会自动生成:
// - public static readonly StyledProperty<string> TextProperty### How can I determine which syntax nodes I should expect?
// - public string Text { get; set; }Consider using the Roslyn Visualizer toolwindow, witch allow you to observe syntax tree.
// - public static readonly StyledProperty<bool> IsEnabledProperty
// - public bool IsEnabled { get; set; }### How to learn more about wiring source generators?
// - public static readonly StyledProperty<double> FontSizePropertyWatch the walkthrough video: [Let’s Build an Incremental Source Generator With Roslyn, by Stefan Pölz](https://youtu.be/azJm_Y2nbAI)
// - public double FontSize { get; set; }The complete set of information is available in [Source Generators Cookbook](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md).
}
2. 高级选项
[StyledProperty("Command", typeof(ICommand), null,
BindsTwoWayByDefault = true,
PropertyChangedCallback = "OnCommandChanged",
CoerceCallback = "CoerceCommand")]
public partial class MyButton : Button
{
private static void OnCommandChanged(AvaloniaObject obj, AvaloniaPropertyChangedEventArgs args)
{
// 属性变更回调
}
private static object CoerceCommand(AvaloniaObject obj, object value)
{
// 值强制转换
return value;
}
}
特性参数
- PropertyName: 属性名称
- PropertyType: 属性类型
- DefaultValue: 默认值(可选)
- BindsTwoWayByDefault: 是否默认双向绑定(可选,默认 false)
- PropertyChangedCallback: 属性变更回调方法名(可选)
- CoerceCallback: 值强制转换回调方法名(可选)
依赖
需要在您的项目中安装:
- Avalonia >= 11.0.0
- FluentIcons.Avalonia >= 1.1.0
许可证
MIT License
作者
HU
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Avalonia (>= 11.0.0)
- FluentIcons.Avalonia (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.