|
|
@ -4,7 +4,7 @@ using XamlX.TypeSystem; |
|
|
|
|
|
|
|
|
namespace Avalonia.Generators.NameGenerator; |
|
|
namespace Avalonia.Generators.NameGenerator; |
|
|
|
|
|
|
|
|
internal class InitializeComponentCodeGenerator: ICodeGenerator |
|
|
internal class InitializeComponentCodeGenerator : ICodeGenerator |
|
|
{ |
|
|
{ |
|
|
private readonly bool _diagnosticsAreConnected; |
|
|
private readonly bool _diagnosticsAreConnected; |
|
|
private const string AttachDevToolsCodeBlock = @"
|
|
|
private const string AttachDevToolsCodeBlock = @"
|
|
|
@ -29,11 +29,20 @@ internal class InitializeComponentCodeGenerator: ICodeGenerator |
|
|
{ |
|
|
{ |
|
|
var properties = new List<string>(); |
|
|
var properties = new List<string>(); |
|
|
var initializations = new List<string>(); |
|
|
var initializations = new List<string>(); |
|
|
|
|
|
const string thisFindNameScopeVariable = " var __thisNameScope__ = this.FindNameScope();"; |
|
|
|
|
|
bool hasNames = false; |
|
|
foreach (var resolvedName in names) |
|
|
foreach (var resolvedName in names) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!hasNames) |
|
|
|
|
|
{ |
|
|
|
|
|
initializations.Add(thisFindNameScopeVariable); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var (typeName, name, fieldModifier) = resolvedName; |
|
|
var (typeName, name, fieldModifier) = resolvedName; |
|
|
properties.Add($" {fieldModifier} {typeName} {name};"); |
|
|
properties.Add($" {fieldModifier} {typeName} {name};"); |
|
|
initializations.Add($" {name} = this.FindNameScope()?.Find<{typeName}>(\"{name}\");"); |
|
|
initializations.Add($" {name} = __thisNameScope__?.Find<{typeName}>(\"{name}\");"); |
|
|
|
|
|
|
|
|
|
|
|
hasNames = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var attachDevTools = _diagnosticsAreConnected && IsWindow(xamlType); |
|
|
var attachDevTools = _diagnosticsAreConnected && IsWindow(xamlType); |
|
|
@ -68,7 +77,7 @@ namespace {nameSpace} |
|
|
}} |
|
|
}} |
|
|
";
|
|
|
";
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static bool IsWindow(IXamlType xamlType) |
|
|
private static bool IsWindow(IXamlType xamlType) |
|
|
{ |
|
|
{ |
|
|
var type = xamlType; |
|
|
var type = xamlType; |
|
|
|