Fixed namspace problem on code generator

This commit is contained in:
Igor Gritsenko 2022-11-20 21:58:00 +03:00
Родитель d7f03eed92
Коммит 31cbaf48a8
4 изменённых файлов: 41 добавлений и 8 удалений

Просмотреть файл

@ -23,7 +23,7 @@ public class AvaloniaPropertyExtensionsGenerator : ISourceGenerator
Debug.WriteLine("Execute AvaloniaPropertyExtensionsGenerator code generator");
var comp = context.Compilation;
var views = GetGenerateExtensionsViews(comp);
var sb = new StringBuilder();
@ -79,11 +79,11 @@ public class AvaloniaPropertyExtensionsGenerator : ISourceGenerator
&& HasPublicSetter(property)
&& IsCommonProperty(property, members))
{
var valueSetterExtensionString = GetCommonPropertySetterExtension(typeName, property);
var valueSetterExtensionString = GetCommonPropertySetterExtension(typeName, property, comp);
if (!string.IsNullOrWhiteSpace(valueSetterExtensionString))
sb.AppendLine(valueSetterExtensionString);
var bindingSetterExtensionString = GetCommonPropertyBindingSetterExtension(typeName, property);
var bindingSetterExtensionString = GetCommonPropertyBindingSetterExtension(typeName, property, comp);
if (!string.IsNullOrWhiteSpace(bindingSetterExtensionString))
sb.AppendLine(bindingSetterExtensionString);
}
@ -200,11 +200,12 @@ public class AvaloniaPropertyExtensionsGenerator : ISourceGenerator
return extensionText;
}
private string GetCommonPropertySetterExtension(string controlTypeName, PropertyDeclarationSyntax property)
private string GetCommonPropertySetterExtension(string controlTypeName, PropertyDeclarationSyntax property,
Compilation compilation)
{
var extensionName = property.Identifier.ToString();
var valueTypeSource = property.Type.ToString();
var valueTypeSource = GetPropertyTypeName(property, compilation);
var argsString = $"{valueTypeSource} value, BindingMode? bindingMode = null, IValueConverter converter = null, object bindingSource = null,"
+ $" [CallerArgumentExpression(\"value\")] string ps = null";
@ -217,10 +218,19 @@ public class AvaloniaPropertyExtensionsGenerator : ISourceGenerator
return extensionText;
}
private string GetCommonPropertyBindingSetterExtension(string controlTypeName, PropertyDeclarationSyntax property)
private string GetPropertyTypeName(PropertyDeclarationSyntax property, Compilation compilation)
{
var semanticModel = compilation.GetSemanticModel(property.SyntaxTree);
var fullTypeName = semanticModel.GetTypeInfo(property.Type).Type?.ToString();
return !string.IsNullOrWhiteSpace(fullTypeName) ? fullTypeName : property.Type.ToString();
}
private string GetCommonPropertyBindingSetterExtension(string controlTypeName, PropertyDeclarationSyntax property,
Compilation compilation)
{
var extensionName = property.Identifier.ToString();
var valueTypeSource = property.Type.ToString();
var valueTypeSource = GetPropertyTypeName(property, compilation);
var extensionText =
$"public static {controlTypeName} {extensionName}"

Просмотреть файл

@ -0,0 +1,6 @@
namespace AvaloniaMarkupSample;
public class CustomBrush : SolidColorBrush
{
}

Просмотреть файл

@ -1,5 +1,21 @@
public class MyCustomControl : ViewBase
using AvaloniaMarkupSample;
public class MyCustomControl : ViewBase
{
#region Background Styled Avalonia Property
public CustomBrush? Background
{
get => GetValue(BackgroundProperty);
set => SetValue(BackgroundProperty, value);
}
public static readonly StyledProperty<CustomBrush?> BackgroundProperty =
AvaloniaProperty.Register<MyCustomControl, CustomBrush?>
(
nameof(Background)
);
#endregion Background Styled Avalonia Property
#region NewValue Styled Avalonia Property
public string? NewValue
{

Просмотреть файл

@ -24,6 +24,7 @@ public class MvuComponent : MvuComponentBase
public int Counter { get; set; }
public string CounterText => $"Counter: {Counter}";
public SampleDataService DataService { get; set; }
private void OnButtonClick(RoutedEventArgs e)
{