Browse Source
* feature: Generate x:Name mapping without the GenerateTypedNameReferences attribute. * fix: Update README.mdpull/10407/head
committed by
GitHub
6 changed files with 129 additions and 22 deletions
@ -0,0 +1,16 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<AvaloniaNameGenerator Condition="'$(AvaloniaNameGenerator)' == ''">true</AvaloniaNameGenerator> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<CompilerVisibleProperty Include="AvaloniaNameGenerator" /> |
|||
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="SourceItemGroup"/> |
|||
</ItemGroup> |
|||
|
|||
<Target Name="_InjectAdditionalFiles" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun"> |
|||
<ItemGroup> |
|||
<AdditionalFiles Include="@(AvaloniaXaml)" SourceItemGroup="AvaloniaXaml" /> |
|||
</ItemGroup> |
|||
</Target> |
|||
</Project> |
|||
@ -0,0 +1,28 @@ |
|||
using Microsoft.CodeAnalysis; |
|||
using System.Linq; |
|||
|
|||
namespace Avalonia.NameGenerator |
|||
{ |
|||
internal static class SourceGeneratorContextExtensions |
|||
{ |
|||
private const string SourceItemGroupMetadata = "build_metadata.AdditionalFiles.SourceItemGroup"; |
|||
|
|||
public static string GetMSBuildProperty( |
|||
this GeneratorExecutionContext context, |
|||
string name, |
|||
string defaultValue = "") |
|||
{ |
|||
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue($"build_property.{name}", out var value); |
|||
return value ?? defaultValue; |
|||
} |
|||
|
|||
public static string[] GetMSBuildItems(this GeneratorExecutionContext context, string name) |
|||
=> context |
|||
.AdditionalFiles |
|||
.Where(f => context.AnalyzerConfigOptions |
|||
.GetOptions(f).TryGetValue(SourceItemGroupMetadata, out var sourceItemGroup) |
|||
&& sourceItemGroup == name) |
|||
.Select(f => f.Path) |
|||
.ToArray(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue