csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.3 KiB
36 lines
1.3 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Avalonia.Generators.Common.Domain;
|
|
using XamlX.TypeSystem;
|
|
|
|
namespace Avalonia.Generators.NameGenerator;
|
|
|
|
internal class OnlyPropertiesCodeGenerator(NamedFieldModifier defaultNamedFieldModifier = NamedFieldModifier.Internal) : ICodeGenerator
|
|
{
|
|
private string _generatorName = typeof(OnlyPropertiesCodeGenerator).FullName;
|
|
private string _generatorVersion = typeof(OnlyPropertiesCodeGenerator).Assembly.GetName().Version.ToString();
|
|
|
|
public string GenerateCode(string className, string nameSpace, IEnumerable<ResolvedName> names)
|
|
{
|
|
var namedControls = names
|
|
.Select(info => " " +
|
|
$"[global::System.CodeDom.Compiler.GeneratedCode(\"{_generatorName}\", \"{_generatorVersion}\")]\n" +
|
|
" " +
|
|
$"{info.FieldModifier ?? defaultNamedFieldModifier.ToString().ToLowerInvariant()} {info.TypeName} {info.Name} => " +
|
|
$"this.FindNameScope()?.Find<{info.TypeName}>(\"{info.Name}\");")
|
|
.ToList();
|
|
var lines = string.Join("\n", namedControls);
|
|
return $@"// <auto-generated />
|
|
|
|
using Avalonia.Controls;
|
|
|
|
namespace {nameSpace}
|
|
{{
|
|
partial class {className}
|
|
{{
|
|
{lines}
|
|
}}
|
|
}}
|
|
";
|
|
}
|
|
}
|
|
|